partition-list
来源:互联网 发布:java 设置useragent 编辑:程序博客网 时间:2024/05/21 06:47
题目:
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,
Given1->4->3->2->5->2and x = 3,
return1->2->2->4->3->5.
程序:
class Solution {public: ListNode *partition(ListNode *head, int x) { if(head == NULL) return head; ListNode* p1 = new ListNode(INT_MIN); ListNode* p2 = new ListNode(INT_MIN); ListNode* pp1 = p1; ListNode* pp2 = p2; ListNode* pNode = head; while(pNode != NULL) { if(pNode->val < x) { pp1->next = pNode; pp1 = pp1->next; } else { pp2->next = pNode; pp2 = pp2->next; } pNode = pNode->next; } pp2->next = NULL; pp1->next = p2->next; return p1->next; }};
阅读全文
0 0
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- Partition List
- 矩阵从左上角到右下角的最优路径使得经过路径上的权值和最大(最小)
- XShell ------ 串口 设置
- [51nod-1120]机器人走方格V3 题解
- usaco6.1.3 Cow XOR
- CodeIgniter Model
- partition-list
- week2
- 《Effective Java》(12~16)阅读笔记
- leetcode-month1-week4
- android调试篇之eclipse 2:调试步骤-断点调试
- ViewPager实现轮播图和小圆点
- python程序的pypy加速
- 顺序表增删改查两种方法---C实现
- sizeof 的简谈