[Leetcode]21. Merge Two Sorted Lists
来源:互联网 发布:sql数值 编辑:程序博客网 时间:2024/06/18 10:30
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
题目很简单,没啥好说的。
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode* ptr = new ListNode(0); ListNode* l3 = ptr; if (l1 == NULL) return l2; if (l2 == NULL) return l1; while (l1 != NULL && l2 != NULL) { if (l1->val <= l2->val) { l3->next = l1; l1 = l1->next; } else { l3->next = l2; l2 = l2->next; } l3 = l3->next; } while (l1) { l3->next = l1; l1 = l1->next; l3 = l3->next; } while (l2) { l3->next = l2; l2 = l2->next; l3 = l3->next; } l3 = ptr->next; delete ptr; return l3; }};
0 0
- 21. Merge Two Sorted Lists leetcode(lists)
- [LeetCode]21.Merge Two Sorted Lists
- LeetCode --- 21. Merge Two Sorted Lists
- LeetCode 21.Merge Two Sorted Lists
- [Leetcode] 21. Merge Two Sorted Lists
- 【LeetCode】21.Merge Two Sorted Lists
- 【leetcode】21. Merge Two Sorted Lists
- [leetcode] 21.Merge Two Sorted Lists
- [leetcode] 21.Merge Two Sorted Lists
- [leetcode] 21. Merge Two Sorted Lists
- <LeetCode OJ> 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists LeetCode
- leetcode 21. Merge Two Sorted Lists
- Leetcode:21. Merge Two Sorted Lists(JAVA)
- Leetcode ☞ 21. Merge Two Sorted Lists
- LeetCode 21. Merge Two Sorted Lists
- [LeetCode]21. Merge Two Sorted Lists
- 【LeetCode】21. Merge Two Sorted Lists
- ADPCM与PCM的区别 以及wave文件的压缩与解压缩
- 微信公众号开发流程
- C#Winform利用DataGridView的特性实现字段排序
- JDBC连接sql server数据库的详细步骤和代码
- android studio去掉标题栏
- [Leetcode]21. Merge Two Sorted Lists
- 双链表队列和栈的实现与操作
- 空指针
- 用Laravel创建项目
- android canvas使用line画半园
- 数组指针与指针数组
- CTF比赛中必备的瑞士军刀ctf-tools
- 个人独立游戏总结
- adpcm的压缩和解压缩实现