LeetCode 86. Partition List
来源:互联网 发布:最有效率的编程语言 编辑:程序博客网 时间:2024/05/22 17:06
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
You should preserve the original relative order of the nodes in each of the two partitions.
For example,
Given 1->4->3->2->5->2
and x = 3,
return 1->2->2->4->3->5
.
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* partition(ListNode *head, int x) { ListNode smaller_head(0); ListNode larger_head(0); ListNode *smaller_tail = &smaller_head; ListNode *larger_tail = &larger_head; while (head != NULL) { if (head->val < x) { smaller_tail->next = head; smaller_tail = head; } else { larger_tail->next = head; larger_tail = head; } head = head->next; } smaller_tail->next = larger_head.next; larger_tail->next = NULL; return smaller_head.next; }};
0 0
- [LeetCode]86.Partition List
- LeetCode 86. Partition List
- [Leetcode] 86. Partition List
- LeetCode --- 86. Partition List
- [leetcode] 86.Partition List
- [leetcode] 86. Partition List
- [LeetCode]86. Partition List
- 86. Partition List LeetCode
- Leetcode 86. Partition List
- LeetCode *** 86. Partition List
- LeetCode 86. Partition List
- [LeetCode]86. Partition List
- LeetCode 86. Partition List
- leetcode 86. Partition List
- Leetcode 86. Partition List
- LeetCode-86.Partition List
- [Leetcode]86. Partition List
- LeetCode - 86. Partition List
- c++ list, vector, map, set 区别与用法比较
- javascript倒计时
- threejs第五篇【一条龙测试之二 threejs基本环境架设】
- 使用训练好的语言模型与声学模型
- 错误
- LeetCode 86. Partition List
- Process.waitFor()的返回值含义
- JSON对象和JSON字符串的相互转换方法
- 安装intelij + scala + sbt,手动、离线、公司
- rapidjson使用样例
- Ubuntu终端下只显示当前目录
- Struts2 OGNL表达式语言
- linux驱动开发 主设备号与次设备号
- 消息队列