摘要:
public static void rotate(int[] nums, int k) { k = k%nums.length; reverse(nums,0,nums.length); reverse(nums,0,k); reverse(nums,k,nums.length); } publi 阅读全文
摘要:
/** * 思想简单,用一个指针指向第二个重复的字符即可,然后判断每一段的大小,通过map保存没有重复字符的索引 */ public static int lengthOfLongestSubstring(String s) { int pre=0,maxlen=0; Map<Character, 阅读全文
摘要:
public static int[] twoSum(int[] nums, int target) { Map<Integer,Integer> map = new HashMap(); int[] a = new int[2]; for (int i = 0; i < nums.length; 阅读全文
摘要:
public static int[] sortedSquares(int[] nums) { //定义一个双指针 int left=0,right=nums.length-1; int[] res = new int[right+1]; //因为新数组需要排序 for (int i = nums. 阅读全文
摘要:
https://leetcode-cn.com/problems/first-bad-version/ public int firstBadVersion(int n) { int left=0,right=n,mid; while (left<right){ mid = ((right-left 阅读全文
摘要:
public static int search(int[] nums, int target) { //双指针 int left=0,right=nums.length-1; int mid=0; int res = -1; while (left<=right){ //防止int溢出如果是写为( 阅读全文
摘要:
package cn.jiedada.controller; import java.util.ArrayList; import java.util.List; import java.util.Stack; /** * 爬楼梯 */ class Solution { public static 阅读全文
摘要:
package cn.jiedada.controller; import java.util.ArrayList; import java.util.List; import java.util.Stack; /** * 数的中序遍历 */ class Solution { public stat 阅读全文
摘要:
三个概念:最有子结构,边界,状态转化 https://www.cnblogs.com/cthon/p/9251909.html 爬楼梯问题 public static int getWay(int i) { if (i<1){ return 1; } if (i==1){ return 1; } i 阅读全文
摘要:
package cn.jiedada.controller; import java.util.ArrayList; import java.util.List; import java.util.Stack; /** * 数的中序遍历 */ class Solution { public List 阅读全文