21. Merge Two Sorted Lists徒手尝试#2(Done)
2016-11-28 15:34
393 查看
Solution
Problem#1
*思路混乱
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode dummy = new ListNode(0); dummy.next = l1; ListNode head = dummy; while(l1 != null && l2 != null) { if(l1.val < l2.val) { head.next = l1; l1 = l1.next; } else { head.next = l2; l2 = l2.next; } head = head.next; } if(l1 == null) { head.next = l2; } if(l2 == null) { head.next = l1; } return dummy.next; } }
Problem#1
*思路混乱
相关文章推荐
- 66. Plus One徒手尝试#2(Done)
- 24. Swap Nodes in Pairs徒手尝试#2(Done)
- 26. Remove Duplicates from Sorted Array徒手尝试#1(Done)
- 19_Remove Nth Node From End of List徒手尝试#2(Done)
- 20_Valid Parentheses徒手尝试#2(Done)
- 27. Remove Element徒手尝试#2(Done)
- 38. Count and Say徒手尝试#2(Done)
- 58. Length of Last Word徒手尝试#2(Done)
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists | Java最短代码实现
- leetcode 21. Merge Two Sorted Lists 两个单向链表合并 指针与解指针
- 9_PalindromeNumber徒手尝试#4(Done)
- 21. Merge Two Sorted Lists leetcode(lists)
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists && 23. Merge k Sorted Lists
- 21. Merge Two Sorted Lists-Python
- 14_LongestCommonPrefix徒手尝试#3(Done)
- 21. Merge Two Sorted Lists | 连接两个有序单链表
- LeetCode 21. Merge Two Sorted Lists
- LeetCode: 21. Merge Two Sorted Lists