`
ouqi
  • 浏览: 41431 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表
还是和removeDuplicateinSortedArr类似的思路 循环不变式   package oj.leetcode; import data.ListNode; /* * 从loop invariant的角度去考虑这个问题。也就能在考虑问题的时候,完成了对算法在数学意义上的证明。 假设,你已经有了一个lessList,一个geList。 然后,就是不断扫描原来的list的各个node,把它们加入到上面两个list之后。 */ public class PatitionList { public ListNode partition(L ...
  public ListNode removeNthFromEnd(ListNode head, int n) { // Start typing your Java solution below // DO NOT write main() function ListNode fast = head; ListNode slow = head; int i = 1; for(;i<=n&&fast.next!=null;i++) fast = fast.next; i ...
思路如下: 假设当前给定permutation序列为 a1 a2 a3...an. 从序列尾部a[n]开始向头部扫描,找到第一个相邻升序序列 a[i-1]< a[i] ; 因为是扫描到的第一个相邻升序,则此时有a[i]>=a[i+1]>=a[i+2]...>=a[n]. 从a[n]逆序遍历至a[i] 找到第一个大于a[i-1]的值a[j] ,交换a[i-1]和a[j].因为a[j]是第一个大于a[i-1]的,所以有a[j+1]至a[n]都小于等于a[i-1]. 即替换后的序列a[1]...a[j],a[i],a[i+1]..a[j-1],a[i-1],a[j+ ...
Search in Rotated Sorted Array  Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory.   思路一(不好,只是为了记录自己的思路轨迹,可忽略不看): 循环遍历链表,循环体: 1. ...
Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i.   If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. 一开始思路: 对于第i天,如果 ...
/* * Merge two sorted linked lists and return it as a new list. * The new list should be made by splicing together the nodes of the first two lists. */ public class MergeTwoSortedList { class ListNode { int val; ListNode next; ListNode(int x) { val ...
转载请注明出处!谢谢 1.       httpClient介绍 HttpClient是一个实现了http协议的开源Java客户端工具库,可以通过程序发送http请求。   1.1.  HttpClient发送请求和接收响应 1.1.1.     
本文也是在查阅了各种资料下总结的,有什么问题还望各位大牛指正~ 一. 基本概念  回调是一种双向调用的模式。被调用方在接口被调用时也会调用对方的接口。恩,具体来说,就是调用者A调用了被调用者B的方法,然后在B的这个方法体内又调用了A的方法。概念听起来很抽象。举个例子说明下,比如今天你去饭店吃饭,可是人满需要排队,于是你在饭店登记了一下(告诉他们你的手机号),告知他们如果有地方了就电话联系你。这是一个回调应用于异步的经典场景。你(调用者)在调用饭店(被调用者)的方法服务时,注册(登记)了自己的方法(电话通知你)。然后在饭店为你服务的过程中,又回调了你这个方法。  这样做有什么好处呢?   1. ...
Global site tag (gtag.js) - Google Analytics