/*
这个题是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;
}

最新文章

  1. SQL中关于日期的常用方法
  2. CLR VIA C#事件
  3. 7.mybatis一对多关联查询
  4. ecshop去官方化的修改
  5. RequireJs 依赖管理使用
  6. javascript 倒计时代码
  7. (转)使用 .NET 的 RNGCryptoServiceProvider 生成随机数
  8. 【2017-05-30】WebForm文件上传
  9. C#开发移动应用系列(4.调用系统应用,以及第三方应用(调用与被调用))
  10. [Swift]LeetCode777. 在LR字符串中交换相邻字符 | Swap Adjacent in LR String
  11. safari图片跨域
  12. php 允许浏览器跨域访问web服务端的解决方案
  13. C++STL 函数对象和谓词
  14. PHP实现菜单无限极分类
  15. SQl查询数据库库名,表名、表的列名
  16. Mac版sublime text右键open in browser 不能识别中文名解决办法
  17. thinkphp框架中Model对象$origin对象的作用
  18. ScrollView 和 ListView 冲突解决方案
  19. iOS12适配指南
  20. .net 导出Excel插件Npoi的使用

热门文章

  1. 重做系统后 恢复oracle 实例
  2. 【JAVA】SSM开源项目源码--城市学院移动后勤-毕业设计(Spring SpringMvc Mybatis Mui Redis )
  3. 性能测试基础——(MEN)
  4. js中的(function(){})()立即执行
  5. 【坑点集合】C++ STL 使用注意事项整理
  6. CF1400F - x-prime Substrings
  7. MySql字符集与排序规则详解
  8. JeecgBoot table 渲染图片
  9. 日期格式化:推荐使用SimpleDateFormat
  10. 一文搞懂Java引用拷贝、浅拷贝、深拷贝