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 ...
随机推荐
- 【BZOJ2648】SJY摆棋子(KD-Tree)
[BZOJ2648]SJY摆棋子(KD-Tree) 题面 BZOJ Description 这天,SJY显得无聊.在家自己玩.在一个棋盘上,有N个黑色棋子.他每次要么放到棋盘上一个黑色棋子,要么放上一 ...
- 20165218 2017-2018-1 《Java程序设计》第一周学习总结
20165218 2017-2018-1 <Java程序设计>第一周学习总结 教材学习内容总结 第一章.Java入门 1. Java特点 Java具有简单.面向对象.平台无关.多线程.动态 ...
- 删边(cip)
删边(cip) 给出一个没有重边和自环的无向图,现在要求删除其中两条边,使得图仍然保持连通. 你的任务是计算有多少组不合法的选边方案.注意方案是无序二元组. Sol 神题,无从下手啊. 考虑点dfs建 ...
- 跨平台sdk接入总结
sdk说明: 1.Bugly SDK:自动捕获上报App的脚本错误和原生代码引发的崩溃信息,并提供异常问题分类分析. 2.语音 SDK:提供游戏内收发语音功能. 接入步骤: step1:仔细通读一遍s ...
- ringbuffer
http://blog.csdn.net/xiaolang85/article/details/38419163
- 线程池 ------ linux C实现
大多数的网络服务器,包括Web服务器都具有一个特点,就是单位时间内必须处理数目巨大的连接请求,但是处理时间却是比较短的.在传统的多线程服务器模型中是这样实现的:一旦有个请求到达,就创建一个新的线程,由 ...
- 使用tcpdump监控网络消息发送
tcpdump是一个用于截取网络分组,并输出分组内容的工具,简单说就是数据包抓包工具.tcpdump凭借强大的功能和灵活的截取策略,使其成为Linux系统下用于网络分析和问题排查的首选工具. tcpd ...
- MyBatis插件及示例----打印每条SQL语句及其执行时间
Plugins 摘一段来自MyBatis官方文档的文字. MyBatis允许你在某一点拦截已映射语句执行的调用.默认情况下,MyBatis允许使用插件来拦截方法调用 Executor(update.q ...
- sql service (case when then else end ..... group by)
1. 原表: courseid coursename score ------------------------------------- 1 java 70 2 oracle 90 3 xml 4 ...
- github访问速度慢,样式加载不完全解决
现象如下图: 解决方案: 绑定host 185.31.17.184 github.global.ssl.fastly.net