博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Partition List
阅读量:4075 次
发布时间:2019-05-25

本文共 897 字,大约阅读时间需要 2 分钟。

Partition List

Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.

You should preserve the original relative order of the nodes in each of the two partitions.

For example,
Given 1->4->3->2->5->2 and x = 3,
return 1->2->2->4->3->5.

Java代码:

/** * Definition for singly-linked list. * public class ListNode { *     int val; *     ListNode next; *     ListNode(int x) { *         val = x; *         next = null; *     } * } */public class Solution {    public ListNode partition(ListNode head, int x) {        ListNode cur=head;        ListNode smaller_sentinel=new ListNode(0);        ListNode smaller_cur=smaller_sentinel;        ListNode larger_sentinel=new ListNode(0);        ListNode larger_cur=larger_sentinel;//Now, go along the list, partitioning into two halves.                while(cur!=null){            if(cur.val
 

转载地址:http://mnuni.baihongyu.com/

你可能感兴趣的文章
UNITY实现FLASH中的setTimeout
查看>>
HOLOLENS 扫描特效 及得出扫描结果(SurfacePlane)
查看>>
矩形旋转一定角度后,四个点的新坐标
查看>>
Unity - RectTransform详解
查看>>
UNITY和图片像素的换算
查看>>
Resources.Load加载文件返回null的原因
查看>>
Introducing Holographic Emulation
查看>>
新手!mass 设置问题
查看>>
AS3语法和UNITY C#语法的异同
查看>>
ACCELEROMETER
查看>>
在后台中高效工作 – 后台任务
查看>>
half extents
查看>>
Unity需要频繁登录是什么情况
查看>>
UNITY自带的PACKAGE的UTILITY 里面有一个自带的FPS COUNTER
查看>>
AssetBundle Manager & Example Scenes
查看>>
fixed数据类型
查看>>
cg数据类型
查看>>
地图四叉树一般用在GIS中,在游戏寻路中2D游戏中一般用2维数组就够了
查看>>
Dijkstra算法(三)之 Java详解
查看>>
float4与half4数据类型
查看>>