Partition List
来源:互联网 发布:网络延迟高怎么解决 编辑:程序博客网 时间:2024/06/08 05:27
/** * 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) { if(!head)return 0; ListNode lhs_dummy(-1); ListNode rhs_dummy(-1); ListNode *lhsTail=&lhs_dummy,*rhsTail=&rhs_dummy; //遍历链表,比x小的插入lhs后,大或等于的插入rhs后 for(ListNode *pNode=head;pNode!=0;pNode=pNode->next) { if(pNode->val<x) { lhsTail->next=pNode; lhsTail=pNode; } else { rhsTail->next=pNode; rhsTail=pNode; } } //合并两个链表 lhsTail->next=rhs_dummy.next; rhsTail->next=0; return lhs_dummy.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
- UVA 644Immediate Decodability
- libsvm代码阅读:基础准备与svm.h头文件
- Template template/*/form-close.ftl not found. - Class: freemarker.template.Configuration
- oracle ORA-12541: TNS:no listener 或者 “ORA-28547:connection to server failed,probable Oracle Net admi
- C# Show()与ShowDialog()的区别
- Partition List
- 内联函数与带参数宏区别(笔记)
- C++类和接口的设计原则探讨
- 图解Android - Android GUI 系统 (2) - 窗口管理 (View, Canvas, Window Manager)
- LA 3027 并查集
- C++写的二叉查找树Tree操作函数
- Android之EditText特殊小技巧
- HeadFirst设计模式 -策略模式
- [iOS]如何向 appstore 查询已发布 APP 的信息?