lintcode 96 链表划分
来源:互联网 发布:单片机简易电子琴7键 编辑:程序博客网 时间:2024/06/05 11:24
给定一个单链表和数值x,划分链表使得所有小于x的节点排在大于等于x的节点之前。
你应该保留两部分内链表节点原有的相对顺序。
2.完全没有思路..........
3./**
* Definition of ListNode
* class ListNode {
* public:
* int val;
* ListNode *next;
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
public:
ListNode *partition(ListNode *head, int x) {
ListNode * small = new ListNode(0); //小于x
ListNode * large = new ListNode(0); //大于x
ListNode * lastSmall = small,* lastLarge = large;
ListNode * cur = head;
while(cur){
if(cur->val < x){
lastSmall->next = cur;
lastSmall = lastSmall->next;
}else{
lastLarge->next = cur;
lastLarge = lastLarge->next;
}
cur = cur->next;
lastSmall->next = lastLarge->next = NULL;
}
lastSmall->next = large->next;
return small->next;
}
};
4.感想
完全不会啊这道题·.有种百度看了答案都不懂得感觉..问问同学.也感觉模模糊糊....
只能先放下这道题.等在学习后再回来看看.
- lintcode 96 链表划分
- LintCode-链表划分
- LintCode:链表划分
- Lintcode 链表划分
- LintCode 链表划分
- 链表划分-LintCode
- LintCode : 链表划分
- 链表划分-LintCode
- [LintCode 96] 链表划分(Python)
- LintCode 96. 链表划分
- [LintCode]96.链表划分
- LintCode Partition List 链表划分
- lintcode——链表划分
- lintcode&九章算法——Lintcode No.96. 链表划分 ? 待解决
- LintCode-数组划分
- LintCode 数组划分
- LintCode:数组划分
- LintCode 数组划分
- 语义网的愿景
- SSH之IDEA2017整合Struts2+Spring+Hibernate
- magento PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate xxxxx)
- SQL复习 2017-3-30
- hive 函数
- lintcode 96 链表划分
- java中final关键字
- l1约束的最小二乘学习
- Bash基本命令
- 最大公约数(gcd):Euclid算法证明
- linux find命令及特殊权限
- Ecshop模板开发(三):insert foreach if标签使用
- 让editplus支持sql编辑
- 【URAL】1554 Multiplicative Functions