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 ...
随机推荐
- POJ3977:Subset——题解(三分+折半搜索)
http://poj.org/problem?id=3977 题目大意:有一堆数,取出一些数,记他们和的绝对值为w,取的个数为n,求在w最小的情况下,n最小,并输出w,n. ————————————— ...
- BZOJ4589:Hard Nim——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4589 Claris和NanoApe在玩石子游戏,他们有n堆石子,规则如下: 1. Claris和N ...
- 无序数组中第Kth大的数
题目:找出无序数组中第Kth大的数,如{63,45,33,21},第2大的数45. 输入: 第一行输入无序数组,第二行输入K值. 该是内推滴滴打车时(2017.8.26)的第二题,也是<剑指of ...
- [学习笔记]分治FFT
一般的分治FFT是指: https://www.luogu.org/problemnew/show/P4721 考虑后面的f和前面的f有关系,但是贡献可以分着计算,逐一累计上去. 考虑cdq分治.算出 ...
- mybatis中parameterType可以写的别名
mybatis中parameterType可以写的别名 https://blog.csdn.net/sdzhangshulong/article/details/51749807 _byte byte ...
- HDU1260DP
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- Qt ---------- connect连接类型
Qt::AutoConnection 0 (Default) If the receiver lives in the thread that emits the signal, Qt::Direct ...
- 解决oracle数据库 ora-00054:resource busy and acquire with NOWAIT specified 错误
解决oracle数据库 ora-00054:resource busy and acquire with NOWAIT specified 错误 本人在使用pl/sql developer 客户端调用 ...
- mysql连接时权限问题 用户问题
启动工程时会连接mysql数据库,此时报错: ERROR 1044 (42000): Access denied for user 'pay'@'localhost' to database 'pay ...
- vs 自定义插件(扩展工具)
此篇仅仅是因为好奇,实现的是完全没有价值的东西,当然,通过此篇的尝试,后续可以在适当的场景,深入的研究Visual Studio自定义插件的应用. 实现功能如下: 在鼠标选中的地方,显示一下创建人,创 ...