随笔分类 -  leetcode

1 2 3 4 5 ··· 8 下一页
leetcode刷题记录
摘要:public int[][] insert(int[][] intervals, int[] newInterval) { int newStart = newInterval[0],newEnd = newInterval[1]; int idx = 0; int n = intervals.le 阅读全文
posted @ 2020-09-02 17:32 欣姐姐 阅读(170) 评论(0) 推荐(0) 编辑
摘要:public String multiply(String num1, String num2) { if(num1.equals("0") || num2.equals("0")){ return "0"; } String res = ""; if(num1.length()<num2.leng 阅读全文
posted @ 2020-09-02 16:21 欣姐姐 阅读(134) 评论(0) 推荐(0) 编辑
摘要:Map<Character,Integer> ori = new HashMap<>(); public boolean checkInclusion(String s1, String s2) { char[] c = s1.toCharArray(); for(char c1:c){ ori.p 阅读全文
posted @ 2020-09-01 10:22 欣姐姐 阅读(181) 评论(0) 推荐(0) 编辑
摘要:Map<Character,Integer> ori = new HashMap<>(); Map<Character,Integer> cnt = new HashMap<>(); //这里用了两个哈希表 public String minWindow(String s, String t) { 阅读全文
posted @ 2020-08-31 20:59 欣姐姐 阅读(143) 评论(0) 推荐(0) 编辑
摘要:用时2分52秒: 用差值进行计算: public int maxProfit(int[] prices) { int n = prices.length; if(n <= 1) return 0; int interest = 0; for(int i = 1;i<n;i++){ int pri = 阅读全文
posted @ 2020-08-05 10:40 欣姐姐 阅读(105) 评论(0) 推荐(0) 编辑
摘要:顺利完成! 思路: 先找0的位置; 判断是否可以跳过位置0。 public boolean canJump(int[] nums) { int n = nums.length; if(n <=1){ return true; } if(nums[0] == 0){ return false; } f 阅读全文
posted @ 2020-08-04 12:05 欣姐姐 阅读(136) 评论(0) 推荐(0) 编辑
摘要:做出来了,但是时间用的比较长。 用了递归。 public void solve(char[][] board) { int m = board.length; if(m == 0){ return; } int n = board[0].length; if(n == 0){ return; } b 阅读全文
posted @ 2020-08-03 14:56 欣姐姐 阅读(108) 评论(0) 推荐(0) 编辑
摘要:自己做的时候老是想着走捷径,其实代码不都是从最复杂最直白的思路开始,然后一步一步进行优化的吗,所以还是不能心急。 这道题我这次没做出来,踏踏实实来。 public List<List<String>> findLadders(String beginWord, String endWord, Lis 阅读全文
posted @ 2020-08-03 12:57 欣姐姐 阅读(136) 评论(0) 推荐(0) 编辑
摘要:图的广度优先遍历,,,没能做出来。。。 public int ladderLength(String beginWord, String endWord, List<String> wordList) { // 先将 wordList 放到哈希表里,便于判断某个单词是否在 wordList 里 Se 阅读全文
posted @ 2020-08-03 10:26 欣姐姐 阅读(153) 评论(0) 推荐(0) 编辑
摘要:递归+回溯 完成! public List<List<Integer>> combine(int n, int k) { if(k>n){ return new ArrayList<>(); } List<List<Integer>> res = new ArrayList<>(); List<In 阅读全文
posted @ 2020-08-02 15:00 欣姐姐 阅读(167) 评论(0) 推荐(0) 编辑
摘要:回溯 public List<List<Integer>> permuteUnique(int[] nums) { List<List<Integer>> result = new ArrayList<>(); boolean[] visited = new boolean[nums.length] 阅读全文
posted @ 2020-07-30 17:33 欣姐姐 阅读(155) 评论(0) 推荐(0) 编辑
摘要:回溯 public List<List<Integer>> permute(int[] nums) { List<List<Integer>> result = new ArrayList<>(); boolean[] visited = new boolean[nums.length]; back 阅读全文
posted @ 2020-07-30 17:08 欣姐姐 阅读(119) 评论(0) 推荐(0) 编辑
摘要:public List<List<Integer>> subsetsWithDup(int[] nums) { Arrays.sort(nums); List<List<Integer>> result = new ArrayList<>(); List<Integer> path = new Ar 阅读全文
posted @ 2020-07-30 16:32 欣姐姐 阅读(138) 评论(0) 推荐(0) 编辑
摘要:递归 public List<List<Integer>> subsets(int[] nums) { Arrays.sort(nums); List<List<Integer>> result = new ArrayList<>(); List<Integer> path = new ArrayL 阅读全文
posted @ 2020-07-30 11:46 欣姐姐 阅读(120) 评论(0) 推荐(0) 编辑
摘要:暴力法,多次循环检查,直到满足条件。 public int candy(int[] ratings) { int[] candies = new int[ratings.length]; Arrays.fill(candies,1); boolean flag = true; int sum = 0 阅读全文
posted @ 2020-07-13 16:04 欣姐姐 阅读(157) 评论(0) 推荐(0) 编辑
摘要:自己完成了,但是效果好像并不怎么样 public int canCompleteCircuit(int[] gas, int[] cost) { int len = gas.length; if(len == 1){ return gas[0] >= cost[0]?0:-1; } int sum1 阅读全文
posted @ 2020-07-13 10:46 欣姐姐 阅读(163) 评论(0) 推荐(0) 编辑
摘要:public void setZeroes(int[][] matrix) { //遍历矩阵,标记要置零的行列,之后进行置零。 ArrayList<Integer> row = new ArrayList<>(); ArrayList<Integer> col = new ArrayList<>() 阅读全文
posted @ 2020-07-10 17:47 欣姐姐 阅读(160) 评论(0) 推荐(0) 编辑
摘要:效率不是很好的样子 回溯 用时一小时15分钟 public List<Integer> grayCode(int n) { List<Integer> list = new ArrayList<>(); if(n == 0){ list.add(0); return list; } //当n>1时 阅读全文
posted @ 2020-07-10 17:28 欣姐姐 阅读(183) 评论(0) 推荐(0) 编辑
摘要:用布尔数组标记是否被访问过,来排查 public boolean isValidSudoku(char[][] board) { //用boolean数组进行标记,是否访问过。 //依次对行列块的数字进行遍历 boolean[] used = new boolean[9]; for(int i = 阅读全文
posted @ 2020-07-10 10:33 欣姐姐 阅读(130) 评论(0) 推荐(0) 编辑
摘要:public String getPermutation(int n, int k) { //itemlist 为原始顺序数列 List<Integer> itemList = new ArrayList<>(); if(n==1){ return "1"; } //阶乘数据 List<Intege 阅读全文
posted @ 2020-07-10 09:51 欣姐姐 阅读(127) 评论(0) 推荐(0) 编辑

1 2 3 4 5 ··· 8 下一页