摘要:
大模拟。。。烦这种题 遇到括号匹配的题目,用栈就对了。此题需要栈+Map 没啥难度,写了半天,Debug几个用例后,1A过了 class Solution { class Atom { String s; int cnt = 1; Atom(String s, int cnt) { this.s = 阅读全文
摘要:
朴素的BFS,注意要考虑输入就是答案的情况 class Solution { class State { int[][] board; int p; int q; int cnt; State(int[][] b, int i, int j) { board = b; p = i; q = j; c 阅读全文
摘要:
二分的一种变种,这次是比较条件改变了,相邻的两位来比较,进而判断左右区间的选择 class Solution { public int peakIndexInMountainArray(int[] arr) { int n = arr.length; int left = 1, right = n 阅读全文
摘要:
二分寻找边界 public class Solution extends VersionControl { public int firstBadVersion(int n) { int i = 1; int j = n; while (i<=j) { int mid = i + ((j-i)>>1 阅读全文
摘要:
考察二分的一种写法,注意数据的溢出 public class Solution extends GuessGame { public int guessNumber(int n) { int left = 1; int right = n; while (left <= right) { int m 阅读全文
摘要:
494. 目标和 一看数据最多才20个,直接暴力DFS感觉能过,没想到真过了o(╯□╰)o class Solution { int ans = 0; public int findTargetSumWays(int[] nums, int target) { int n = nums.length 阅读全文
摘要:
考察栈的使用,需要注意边界情况。不难,想全TestCase很容易1A通过 class Solution { public String reverseParentheses(String s) { Stack<Character> stack = new Stack<>(); if (s.lengt 阅读全文