上一页 1 2 3 4 5 6 ··· 17 下一页
摘要: Stack solution: class Solution { public int scoreOfParentheses(String s) { Stack<Integer> st = new Stack<>(); int score = 0; for(int i = 0; i < s.leng 阅读全文
posted @ 2022-04-19 10:19 阳光明媚的菲越 阅读(12) 评论(0) 推荐(0) 编辑
摘要: My first solution, time complexityO(m*n), where m is the cell number of mat1, and n is the cell number of mat2: class Solution { public int[][] multip 阅读全文
posted @ 2022-04-19 08:15 阳光明媚的菲越 阅读(14) 评论(0) 推荐(0) 编辑
摘要: My first binary search solution: class Solution { public int findKthPositive(int[] arr, int k) { int l=0, r = arr.length-1; while(l+1<r){ int mid = (l 阅读全文
posted @ 2022-04-19 06:53 阳光明媚的菲越 阅读(14) 评论(0) 推荐(0) 编辑
摘要: My solution: class Solution { public int missingElement(int[] nums, int k) { int i=1; for(;i<nums.length;i++){ int diff = nums[i]-nums[i-1]-1; if(diff 阅读全文
posted @ 2022-04-14 11:43 阳光明媚的菲越 阅读(13) 评论(0) 推荐(0) 编辑
摘要: class TicTacToe { int n; int[] rows; int[] cols; int diag=0; int antiDiag = 0; public TicTacToe(int n) { this.n = n; rows = new int[n]; cols = new int 阅读全文
posted @ 2022-04-14 05:29 阳光明媚的菲越 阅读(18) 评论(0) 推荐(0) 编辑
摘要: The key to solve this problem is to find the path from root to target, and put the length to target of every node from root to target to a map. Then e 阅读全文
posted @ 2022-04-14 05:11 阳光明媚的菲越 阅读(14) 评论(0) 推荐(0) 编辑
摘要: PreOrder: class Solution { double min = Integer.MAX_VALUE; int val; public int closestValue(TreeNode root, double target) { preOrder(root, target); re 阅读全文
posted @ 2022-04-14 02:47 阳光明媚的菲越 阅读(10) 评论(0) 推荐(0) 编辑
摘要: This is a merge interval's variety: class Solution { public String addBoldTag(String s, String[] words) { List<int[]> intervals = new ArrayList<>(); f 阅读全文
posted @ 2022-04-14 02:29 阳光明媚的菲越 阅读(20) 评论(0) 推荐(0) 编辑
摘要: My solution, using stack: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode( 阅读全文
posted @ 2022-04-12 12:34 阳光明媚的菲越 阅读(14) 评论(0) 推荐(0) 编辑
摘要: BFS, using PriorityQueue to poll out the smallest number every time. The largest number you get will be the result. class Solution { public int swimIn 阅读全文
posted @ 2022-04-12 07:30 阳光明媚的菲越 阅读(9) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 17 下一页