21. Merge Two Sorted Lists (Easy)
来源:互联网 发布:dbaccess 执行sql 编码 编辑:程序博客网 时间:2024/05/17 07:08
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.
Solution:
C:
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) { if(!l1 && !l2) { return NULL; } if(l1 && !l2) { return l1; } if(!l1 && l2) { return l2; } struct ListNode* p; if(l1->val < l2->val) { p = l1; l1 = l1->next; } else { p = l2; l2 = l2->next; } struct ListNode* list = p; while(l1 && l2) { if(l1->val < l2->val) { p->next = l1; p = l1; l1 = l1->next; } else { p->next = l2; p = l2; l2 = l2->next; } } if(l1) { p->next = l1; } if(l2) { p->next = l2; } return list;}
0 0
- 21. Merge Two Sorted Lists [easy] (Python)
- 21. Merge Two Sorted Lists (Easy)
- LeetCode 21. Merge Two Sorted Lists (Easy)
- Merge Two Sorted Lists (EASY)
- Leet Code OJ 21. Merge Two Sorted Lists [Difficulty: Easy]
- Easy-题目23:21. Merge Two Sorted Lists
- Leetcode 21. Merge Two Sorted Lists (Easy) (cpp)
- 21. Merge Two Sorted Lists(Linked List-Easy)
- [Leetcode 21, Easy] Merge Two Sorted Lists
- Merge Two Sorted Lists(easy)
- 【Leetcode-Easy-21】Merge Two Sorted Lists
- 21.Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21.Merge Two Sorted Lists
- Java爬虫网页抓取图片
- iptables+tc实现isp级别每ip限速并限制会话数
- 用 shell 脚本快速打包 iOS ipa 文件
- Android开发-RecyclerView-AndroidStudio(五)属性动画(2)MoveDuration
- JDK安装成功了 但eclipse起不来
- 21. Merge Two Sorted Lists (Easy)
- Xcode 8.0 调试运行,This ** is running iOS 10.1.1 (14B100), which may not be supported
- 你应该知道的active code,关于cmd黑窗口那些事儿
- 后HTML5时代Ⅱ(转)
- 启动Tomcat出现错误:严重: Error initializing endpoint ;严重: Catalina.start 等的解决
- 细说javascript作用域
- 51822功率设置
- 自定义ViewGroup
- 错误解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file