摘要:
思路:使用栈后进先出的特殊结构,对括号进行匹配,每次执行stack.push()后当前循环结束开始下一次循环 public boolean KuoHao(String str){ Stack<Character> stack = new Stack<>(); for(char s : str.toC 阅读全文
摘要:
思路:快慢指针 代码如下: public ListNode inNode(ListNode head){ ListNode slow = head;//慢指针 ListNode fast = head;//快指针 while(fast!=null&&fast.next!=null){ fast = 阅读全文
摘要:
思路:采用快慢指针,若有环 快慢指针一定会在某处相等 public boolean checkCycle(ListNode head){ if(head==null) return fasle; ListNode slow = head; ListNode fast = head; while(fa 阅读全文
摘要:
一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个 n 级的台阶总共有多少种跳法(先后次序不同算不同的结果)。 思路:逆向思维 ;如果我从第n个台阶进行下台阶,下一步有2中可能,一种走到第n-1个台阶,一种是走到第n-2个台阶。 即 F(n) = F(n-1)+F(n-2); pubul 阅读全文
摘要:
思路:递归 public ListNode Merge(ListNode node1,ListNode node2){ if(node1==null) return node2; if(node2==null) return node1; if(node1.val<=node2.val){ node 阅读全文
摘要:
public int[] addNumber(int[]arr,int target){ int res[] = new int[2];//定义返回下标数组 Map<Integer,Integer> map = new HashMap<>(); for(int i=0;i<arr.length;i+ 阅读全文
摘要:
思路:LRU(最近最少使用)当输入arr[][] = [[1,1,1],[1,2,2],[2,1],[1,3,4]] 其中二维数组a[x][0]代表操作,如[1,1,1] : set(1,1);[2,1] : get(1) public int[] LRU(int [][]arrs, int k){ 阅读全文
摘要:
目的:将两个String类型的数相加返回一个String类型数据 public String maxAdd(String s,String t){ int tmp=0;//进位数 int sl = s.length()-1; int tl = t.length()-1; StringBuffer s 阅读全文
摘要:
思想:使用两个指针,返回符合条件且指针之间距离最大的 public int maxArr(int[]arr){ int tmp = 0;//创建一个临时存放值 int rest = 0;//返回最大长度 for(int right=0;right<arr.length;i++){//右边指针 int 阅读全文
摘要:
思路:快速排序 public int searchK(int arr[],int n,int k){ return find(arr,0,n-1,k); } public int find(int arr[],int low,int high,int k){ int flag = sortFlag( 阅读全文