leetcode Partition List
来源:互联网 发布:c 在线客服系统源码 编辑:程序博客网 时间:2024/06/15 02:54
开辟两个链表分别存放小于和大于等于x的结点
代码
class Solution {public: ListNode *partition(ListNode *head, int x) { if(head==NULL) return head; ListNode * smallHead = new ListNode(0); ListNode * bigHead = new ListNode(0); ListNode * p = head; ListNode *q1, *q2; q1 = smallHead; q2 = bigHead; while(p!=NULL) { ListNode * tempNode = new ListNode(p->val); if(p->val<x) { q1->next = tempNode; q1 = tempNode; } else { q2->next = tempNode; q2 = tempNode; } p = p->next; } q1 = smallHead; while(q1->next!=NULL) q1 = q1->next; q1->next = bigHead->next; return smallHead->next; }};
0 0
- LeetCode: Partition List
- LeetCode Partition List
- LeetCode: Partition List
- [Leetcode] Partition List **
- [Leetcode] Partition List
- [LeetCode] Partition List
- leetcode 81: Partition List
- [Leetcode] Partition List
- leetcode 118: Partition List
- [LeetCode]Partition List
- [leetcode]Partition List
- LeetCode-Partition List
- [leetcode] Partition List
- LeetCode - Partition List
- [LeetCode] Partition List
- LeetCode 86: Partition List
- LeetCode:Partition List
- 【leetcode】Partition List
- java 中list,set,map集合的用法和区别
- Hibernate缓存机制和四种状态
- hdu 2120 Ice_cream's world I
- RoBa's blogProgramming, algorithm, and daily lifeRe: 真的ACM很有用么?
- hdu 2119 Matrix(二分最大匹配)
- leetcode Partition List
- 矩阵的快速幂
- LeetCode Maximum Subarray
- 从QQ登录的js sdk中,研究html、css以及js的解耦
- java中IO流总结之五:RandomAccessFile类的用法总结
- Linux下64位weblogic11g的安装
- POJ3225Help with Intervals
- I2S音频总线学习(一)数字音频技术
- poj 3744