Leetcode 21. Merge Two Sorted Lists (Easy) (cpp)
来源:互联网 发布:采集数据犯法吗 编辑:程序博客网 时间:2024/05/21 01:30
Leetcode 21. Merge Two Sorted Lists (Easy) (cpp)
Tag: Linked List
Difficulty: Easy
/*21. Merge Two Sorted Lists (Easy)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* dummy = new ListNode(-1); for (ListNode* p = dummy; l1 != NULL || l2 != NULL; p = p -> next) { if (l1 == NULL || l2 != NULL && l2 -> val < l1 -> val) { p -> next = l2; l2 = l2 -> next; } else { p -> next = l1; l1 = l1 -> next; } } return dummy -> next; }};
0 0
- Leetcode 21. Merge Two Sorted Lists (Easy) (cpp)
- LeetCode 21. Merge Two Sorted Lists (Easy)
- [Leetcode 21, Easy] Merge Two Sorted Lists
- 【Leetcode-Easy-21】Merge Two Sorted Lists
- 21. Merge Two Sorted Lists [easy] (Python)
- 21. Merge Two Sorted Lists (Easy)
- 21. Merge Two Sorted Lists leetcode(lists)
- Merge Two Sorted Lists (EASY)
- [LeetCode] 021. Merge Two Sorted Lists (Easy) (C++/Python)
- LeetCode-21-Merge Two Sorted Lists(链表/归并)-Easy
- LeetCode OJ 21 Merge Two Sorted Lists [Easy]
- LeetCode-Easy刷题(6) Merge Two Sorted Lists
- leetcode 日经贴,Cpp code -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
- 将图片插入到页面的方法
- C++打包DLL在C#中调用
- Ubuntu环境安装Qt4和使用Qt4初体验(转载)
- ExpandableListView设置分割线的颜色
- 简直粗爆 opencv 2.4.9 + vs 2010 或者vs 2012 环境配置
- Leetcode 21. Merge Two Sorted Lists (Easy) (cpp)
- 每天一个linux命令:ln 命令
- Servelet-页面乱码(非英文字符全部是问号)
- Ubuntu14.04+CUDA7.5+Anaconda2-4.0.0+Matlab2014b+Caffe from Scratch
- (js)强制不使用“兼容性视图”
- Jsp中的自定义标签
- ASCLL一览表
- 打开树莓派3b(ubuntu16.04 mate)的spi配置
- Leetcode 19. Remove Nth Node From End of List (Easy) (cpp)