摘要: public char firstUniqChar(String s) { if(s.equals(" "))return ' '; int[] arr = new int[26]; for(int i = 0 ; i < s.length() ; i++) { arr[s.charAt(i) - 阅读全文
posted @ 2020-07-13 09:12 贼心~不死 阅读(105) 评论(0) 推荐(0) 编辑
摘要: class MinStack { Stack<Integer> data; Stack<Integer> helper; /** initialize your data structure here. */ public MinStack() { data = new Stack<Integer> 阅读全文
posted @ 2020-07-12 16:18 贼心~不死 阅读(92) 评论(0) 推荐(0) 编辑
摘要: public static int[][] direction = new int[][]{{0,-1},{0,1},{1,0},{-1,0}}; public boolean exist(char[][] board, String word) { //dfs int m = board.leng 阅读全文
posted @ 2020-07-11 13:36 贼心~不死 阅读(122) 评论(0) 推荐(0) 编辑
摘要: public int minArray(int[] numbers) { //二分法 int n = numbers.length; int i = 0 , j = n -1; while(i < j) { int mid = i + ((j-i) >> 1); if(numbers[mid] > 阅读全文
posted @ 2020-07-11 13:06 贼心~不死 阅读(101) 评论(0) 推荐(0) 编辑
摘要: public boolean findNumberIn2DArray(int[][] matrix, int target) { int m = matrix.length; if(0 == m || null == matrix)return false; int n = matrix[0].le 阅读全文
posted @ 2020-07-11 10:03 贼心~不死 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 先用set去重: public boolean wordBreak(String s, List<String> wordDict) { //dp int n = s.length(); boolean[] dp = new boolean[n+1]; dp[0] = true; Set<Strin 阅读全文
posted @ 2020-07-09 10:11 贼心~不死 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 直接dp public int respace(String[] dictionary, String sentence) { int n = sentence.length(); if(0==n)return 0; int[] dp = new int[n+1]; for(int i = 1 ; 阅读全文
posted @ 2020-07-09 08:51 贼心~不死 阅读(184) 评论(0) 推荐(0) 编辑
摘要: public int minSubArrayLen(int s, int[] nums) { if( 0 == nums.length || null == nums) { return 0; } int l = 0 ; int r = 0; int result = Integer.MAX_VAL 阅读全文
posted @ 2020-07-08 16:56 贼心~不死 阅读(122) 评论(0) 推荐(0) 编辑
摘要: public int sumNums(int n) { boolean flag = (n > 0) && ( ( n += sumNums(n-1)) > 0 ); return n; } 利用&&的短路特性。 阅读全文
posted @ 2020-07-08 16:07 贼心~不死 阅读(89) 评论(0) 推荐(0) 编辑
摘要: public ListNode removeNthFromEnd(ListNode head, int n) { ListNode slow = head; ListNode fast = head; //快指针先走n-1步 int i = 1; while(i <= n) { fast = fas 阅读全文
posted @ 2020-07-08 15:50 贼心~不死 阅读(80) 评论(0) 推荐(0) 编辑