[LeetCode]86. Partition List分离链表
2024-10-19 01:58:33
/*
这个题是medium的意思应该是用双指针的方法做,如果使用下边的新建链表的方法,就是easy的题目了
双指针会用到很多链表的相连操作
*/
public ListNode partition(ListNode head, int x) {
ListNode s = null;
ListNode b = null;
ListNode temp=null,res=null;
while (head!=null)
{
int cur = head.val;
if (head.val<x)
{
if (s==null) {
s = new ListNode(cur);
res = s;
}
else {
s.next = new ListNode(cur);
s = s.next;
}
}
else
{
if (b==null) {
b = new ListNode(cur);
temp = b;
}
else {
b.next = new ListNode(cur);
b = b.next;
}
}
head = head.next;
}
if (s==null) return temp;
s.next = temp;
return res;
}
最新文章
- SQL中关于日期的常用方法
- CLR VIA C#事件
- 7.mybatis一对多关联查询
- ecshop去官方化的修改
- RequireJs 依赖管理使用
- javascript 倒计时代码
- (转)使用 .NET 的 RNGCryptoServiceProvider 生成随机数
- 【2017-05-30】WebForm文件上传
- C#开发移动应用系列(4.调用系统应用,以及第三方应用(调用与被调用))
- [Swift]LeetCode777. 在LR字符串中交换相邻字符 | Swap Adjacent in LR String
- safari图片跨域
- php 允许浏览器跨域访问web服务端的解决方案
- C++STL 函数对象和谓词
- PHP实现菜单无限极分类
- SQl查询数据库库名,表名、表的列名
- Mac版sublime text右键open in browser 不能识别中文名解决办法
- thinkphp框架中Model对象$origin对象的作用
- ScrollView 和 ListView 冲突解决方案
- iOS12适配指南
- .net 导出Excel插件Npoi的使用
热门文章
- 重做系统后 恢复oracle 实例
- 【JAVA】SSM开源项目源码--城市学院移动后勤-毕业设计(Spring SpringMvc Mybatis Mui Redis )
- 性能测试基础——(MEN)
- js中的(function(){})()立即执行
- 【坑点集合】C++ STL 使用注意事项整理
- CF1400F - x-prime Substrings
- MySql字符集与排序规则详解
- JeecgBoot table 渲染图片
- 日期格式化:推荐使用SimpleDateFormat
- 一文搞懂Java引用拷贝、浅拷贝、深拷贝