leetcode 之Partition List(16)
思路就是定义两个链表,一个放大的,一个放小的,最后将两个连起来,注意细节问题。
ListNode *partionList(ListNode *head, int value)
{
ListNode left_dummy(-);
ListNode right_dummy(-); auto left_cur = left_dummy.next;
auto right_cur = right_dummy.next;
for (ListNode *cur = head; cur != nullptr; cur = cur->next)
{
if (cur->val > value)
{
left_cur->next = cur;
left_cur = cur;
}
else
{
right_cur->next = cur;
right_cur = cur;
}
} left_cur->next = right_dummy.next;
right_cur->next = nullptr;
return left_dummy.next;
}
leetcode 之Partition List(16)的更多相关文章
- LeetCode: Palindrome Partition
LeetCode: Palindrome Partition Given a string s, partition s such that every substring of the partit ...
- leetcode面试题 17.16. 按摩师
leetcode面试题 17.16. 按摩师 又一道动态规划题目 动态规划的核心就是总结出一个通行的方程. 但是这道题似乎不太适合使用递归的方式. 所以使用for循环遍历数组. class Solut ...
- [LeetCode] 915. Partition Array into Disjoint Intervals 分割数组为不相交的区间
Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...
- [LeetCode] 763. Partition Labels 分割标签
A string S of lowercase letters is given. We want to partition this string into as many parts as pos ...
- [LeetCode] 416. Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- LeetCode 1043. Partition Array for Maximum Sum
原题链接在这里:https://leetcode.com/problems/partition-array-for-maximum-sum/ 题目: Given an integer array A, ...
- [LeetCode] 86. Partition List 划分链表
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- leetcode 86. Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- 【leetcode】Partition List
Partition List Given a linked list and a value x, partition it such that all nodes less than x come ...
随机推荐
- ssm框架pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- POJ1375:Intervals——题解
http://poj.org/problem?id=1375 题目大意:有一盏灯,求每段被圆的投影所覆盖的区间. —————————————————————— 神题,卡精度,尝试用各种方法绕过精度都不 ...
- BZOJ2242:[SDOI2011]计算器——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=2242 https://www.luogu.org/problemnew/show/P2485 你被 ...
- Flex 布局教程:实例篇【转】
Flex 布局教程:实例篇 作者: 阮一峰 日期: 2015年7月14日 原文:http://www.ruanyifeng.com/blog/2015/07/flex-examples.html ...
- ClusterId read in ZooKeeper is null 处理
ClusterId read in ZooKeeper is null. Re-running the program after fixing issue 1 will result in the ...
- mac os x之解决npm安装包失败,或者nodejs工程缺少依赖
在国内做开发,由于各种各样的原因,导致网络总是那么不好,对于我们前端开发者,在使用npm的时候很可能因为网络问题导致包安装失败,然后我们又匆匆启动项目,导致缺少依赖等各种问题,下面将会介绍一个淘宝的n ...
- JAVA--结果集已耗尽
有两个可能 1.rs ,state和conn没有关闭 rs.close(); state.close(); conn.close(); if(rs!=null) rs.close; if(sta ...
- Windows/Linux javac/java编译运行引入所需的jar包
> Windows 假设要引用的jar放在D:/test目录下,名字为t1.jar, java源文件放在D:/test/src目录下,名字为t2.java. 编译: javac -cp d: ...
- Frogs' Neighborhood(POJ1659+Havel-Hakimi定理)
题目链接:http://poj.org/problem?id=1659 题目: 题意:根据他给你的每个点的度数构造一张无向图. 思路:自己WA了几发(好菜啊……)后看到discuss才知道这个要用Ha ...
- windows10安装oracle11g报错ORA-01034、ORA-01078
ORA-01034表示数据库实例未建立,可以先用管理员账号进入一个空白实例 sqlplus / as sysdba; 如果您当前使用的账号是安装oracle的账号,则不需要账号密码就可以登陆oracl ...