思路就是定义两个链表,一个放大的,一个放小的,最后将两个连起来,注意细节问题。

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)的更多相关文章

  1. LeetCode: Palindrome Partition

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

  2. leetcode面试题 17.16. 按摩师

    leetcode面试题 17.16. 按摩师 又一道动态规划题目 动态规划的核心就是总结出一个通行的方程. 但是这道题似乎不太适合使用递归的方式. 所以使用for循环遍历数组. class Solut ...

  3. [LeetCode] 915. Partition Array into Disjoint Intervals 分割数组为不相交的区间

    Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...

  4. [LeetCode] 763. Partition Labels 分割标签

    A string S of lowercase letters is given. We want to partition this string into as many parts as pos ...

  5. [LeetCode] 416. Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  6. LeetCode 1043. Partition Array for Maximum Sum

    原题链接在这里:https://leetcode.com/problems/partition-array-for-maximum-sum/ 题目: Given an integer array A, ...

  7. [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 ...

  8. 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 ...

  9. 【leetcode】Partition List

    Partition List Given a linked list and a value x, partition it such that all nodes less than x come ...

随机推荐

  1. 洛谷 P4735 最大异或和 解题报告

    P4735 最大异或和 题目描述 给定一个非负整数序列\(\{a\}\),初始长度为\(N\). 有\(M\)个操作,有以下两种操作类型: A x:添加操作,表示在序列末尾添加一个数\(x\),序列的 ...

  2. IDEA_MyBatis_SQLException:Parameter index out of range坑

    报错信息:超出数据库数据表设定的规定长度了 nested exception is org.apache.ibatis.type.TypeException: Could not set parame ...

  3. 使用 Intel HAXM 为eclipse安卓模拟器加速

    一.下载haxm安装 https://software.intel.com/zh-cn/android/articles/intel-hardware-accelerated-execution-ma ...

  4. js ajax向后台传数组可以直接拼接传输

    ajax向后台传数组是可以直接传的,写法如下 var ids = [ ]; $(dom1).each(function(){ ids.push($(this).val()); }); var  use ...

  5. selenium-控制浏览器操作

    from selenium import webdriver driver = webdriver.Chrome() #打开浏览器 driver.get(urlname) #控制浏览器窗口大小 dri ...

  6. nfs挂载权限问题

    问题: 服务器A:192.168.10.230 服务器B:192.168.10.231 由于服务器A空间不足,打算将服务器A产生的数据库日志挂载到服务器B上,刚开始设定的anonuid和anongid ...

  7. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

  8. UITableView的代理方法

    一.点击某个cell调用 /** * 点击了第几行调用 */ -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NS ...

  9. asp.net 文件上传,大文件上传。

    新建一个asp.net页面,在工具栏里拖入 FileUpload 上传控件.一个按钮 Button  !    !     ! 进入Button事件 //----------------------- ...

  10. Mysql优化小记1

    在项目开发中,需要写个windows服务从sqlserver复制数据到mysql(5.6.13 Win64(x86_64)),然后对这些数据进行计算分析.每15分钟复制一次,每次复制大概200条数据, ...