http://oj.leetcode.com/problems/partition-list/

链表的处理

#include <iostream>
using namespace std; struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
}; class Solution {
public:
ListNode *partition(ListNode *head, int x) {
ListNode *head1 = NULL,*head2 = NULL,*tail1 = NULL,*tail2 = NULL,*p = NULL;
p = head;
bool flag1 = ,flag2 = ;
while(p)
{
if(p->val<x)
{
if(flag1 == )
{
head1 = tail1 = p;
flag1 = ;
}
else
{
tail1->next = p;
tail1 = p;
}
}
else
{
if(flag2 == )
{
head2 = tail2 = p;
flag2 = ;
}
else
{
tail2->next = p;
tail2 = p;
}
}
p = p->next;
}
if(head1 == tail1 && tail1 == NULL)
return head2;
tail1->next = head2;
if(tail2)
tail2->next = NULL;
return head1; }
}; int main()
{
ListNode *n1 = new ListNode();
ListNode *n2 = new ListNode();
ListNode *n3 = new ListNode();
ListNode *n4 = new ListNode();
ListNode *n5 = new ListNode();
ListNode *n6 = new ListNode();
n1->next = n2;
n2->next = n3;
n3->next = n4;
n4->next = n5;
n5->next = n6;
ListNode *ans;
Solution myS;
ans = myS.partition(NULL,);
return ;
}

LeetCode OJ--Partition List的更多相关文章

  1. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  2. LeetCode: Palindrome Partition

    LeetCode: Palindrome Partition Given a string s, partition s such that every substring of the partit ...

  3. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  4. 【LeetCode OJ】Reverse Words in a String

    Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...

  5. LeetCode OJ学习

    一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...

  6. LeetCode OJ 297. Serialize and Deserialize Binary Tree

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  7. 备份LeetCode OJ自己编写的代码

    常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...

  8. LeetCode OJ 之 Maximal Square (最大的正方形)

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...

  9. LeetCode OJ:Integer to Roman(转换整数到罗马字符)

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  10. LeetCode OJ:Serialize and Deserialize Binary Tree(对树序列化以及解序列化)

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

随机推荐

  1. numpy中tile函数

    tile函数位于python模块numpy.lib.shape_base中,他的功能是重复某个数组. 函数的形式是tile(A,reps) 函数参数说明中提到A和reps都是array_like的,什 ...

  2. ios之UISplitViewController

    iPad的屏幕比iPhone大,所以在界面上,iPad比iPhone多一个UISplitViewController,用来实现iPad在横屏时,分两栏显示所需要的界面,可以一边是目录一边是具体的内容. ...

  3. Alert and Action sheets and Timer and Animation

  4. 使用custom elements和Shadow DOM自定义标签

    具体的api我就不写 官网上面多  如果不知道这个的话也可以搜索一下 目前感觉这个还是相当好用的直接上码. <!DOCTYPE html> <html lang="en&q ...

  5. 【动态规划】bzoj2298: [HAOI2011]problem a

    建模超级妙…… Description 一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话(可能有相同的分数) Input 第一行一个整数n,接 ...

  6. IE8 png图片黑色阴影的解决方案!

    以前都没有留意这个问题,最近开发中才发现. 什么情况下会出现黑边? PNG透明图片,同时有阴影,具备着两个IE8是不会有问题的,再加上使用了 “渐变显示”,就会出现了. 解决方法: img{displ ...

  7. python基础知识13-迭代器与生成器,导入模块

    异常处理作业讲解 file = open('/home/pyvip/aaa.txt','w+') try: my_dict = {'name':'adb'} file.write(my_dict['a ...

  8. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  9. SVN如何避免冲突

    在团队开发时,必然会用到代码版本控制工具,比如SVN. 但是多人共同维护同一份代码,当对同一文件进行增删时,就可能造成冲突,如何尽可能避免冲突相当重要. 首先,每次,新建任何文档,都会修改项目文件,所 ...

  10. python基础——14(shelve/shutil/random/logging模块/标准流)

    一.标准流 1.1.标准输入流 res = sys.stdin.read(3) 可以设置读取的字节数 print(res) res = sys.stdin.readline() print(res) ...