-
21. Merge Two Sorted ListsAlgorithm/java tip 2021. 3. 13. 16:29
leetcode.com/problems/merge-two-sorted-lists/
class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode ret = null; if(l1 == null) return l2; if(l2 == null) return l1; if(l1.val < l2.val) { l1.next = mergeTwoLists(l1.next, l2); return l1; } else { l2.next = mergeTwoLists(l1, l2.next); return l2; } } }
'Algorithm > java tip' 카테고리의 다른 글
797. All Paths From Source to Target (0) 2021.03.20 98. Validate Binary Search Tree (0) 2021.03.14 530. Minimum Absolute Difference in BST (0) 2021.03.13 589. N-ary Tree Preorder Traversal (0) 2021.03.13 78. Subsets (0) 2021.03.07