[LintCode]96.链表划分
来源:互联网 发布:德国表现主义电影知乎 编辑:程序博客网 时间:2024/05/21 18:36
给定一个单链表和数值x,划分链表使得所有小于x的节点排在大于等于x的节点之前。
你应该保留两部分内链表节点原有的相对顺序。
样例
给定链表 1->4->3->2->5->2->null,并且 x=3
返回 1->2->2->4->3->5->null
/** * Definition of ListNode * class ListNode { * public: * int val; * ListNode *next; * ListNode(int val) { * this->val = val; * this->next = NULL; * } * } */class Solution {public: /* * @param head: The first node of linked list * @param x: An integer * @return: A ListNode */ ListNode * partition(ListNode * head, int x) { ListNode* minList= new ListNode(0); ListNode* maxList= new ListNode(0); ListNode* min = minList, *max=maxList; ListNode* current=head; while(current){ if(current->val < x){ min->next = current; min = min->next; } else{ max->next = current; max = max->next; } current = current->next; } min->next= maxList->next; max->next = NULL; return minList->next; }};
阅读全文
0 0
- LintCode 96. 链表划分
- [LintCode]96.链表划分
- LintCode-链表划分
- LintCode:链表划分
- Lintcode 链表划分
- LintCode 链表划分
- 链表划分-LintCode
- LintCode : 链表划分
- 链表划分-LintCode
- lintcode 96 链表划分
- lintcode&九章算法——Lintcode No.96. 链表划分 ? 待解决
- LintCode Partition List 链表划分
- lintcode——链表划分
- [LintCode 96] 链表划分(Python)
- LintCode-数组划分
- LintCode 数组划分
- LintCode:数组划分
- LintCode 数组划分
- Java线程池(ThreadPoolFactory)构造参数总结
- 基于 Excel 参数化你的 Selenium2 测试代码
- synchronized同步代码块
- Codeforces-809C Find a car(分治)
- mac 下终端访问文件出现“Permission Denied”解决方案
- [LintCode]96.链表划分
- POJ-1742:Coins(多重背包二进制求法)
- Eclipse上Maven环境配置使用
- AESTool
- Spring自定义Listener(监听器)的使用
- 页面静态资源做cdn之后的字体图标不显示的问题
- Guitar Pro基础教程:如何打开吉他面板功能
- [小白]java:日期对象转换用法(string,int)
- CSS学习之CSS Syntax