面试题 16.15. 珠玑妙算
先算猜中数,再算伪猜中数,伪猜中数=两个序列相同的字符数-猜中数
两个序列相同的字符数 = map中相同的key对应的较小的那个value
299. 猜数字游戏
36. 有效的数独
class Solution {public boolean isValidSudoku(char[][] board) {int[][] rows = new int[9][9];int[][] columns = new int[9][9];int[][][] subboxes = new int[3][3][9];for (int i = 0; i < 9; i++) {for (int j = 0; j < 9; j++) {char c = board[i][j];if (c != '.') {//注意这里,想用字符的数字当下标一定得减'0',减1是为了从0开始int index = c - '0' - 1;rows[i][index]++;columns[j][index]++;subboxes[i / 3][j / 3][index]++;if (rows[i][index] > 1 || columns[j][index] > 1 || subboxes[i / 3][j / 3][index] > 1) {return false;}}}}return true;}}
575. 分糖果
剑指 Offer 61. 扑克牌中的顺子
202. 快乐数
class Solution {public boolean isHappy(int n) {Set<Integer> record = new HashSet<>();while (n != 1 && !record.contains(n)) { //这里判断思路比我更好一点record.add(n);n = getNextNumber(n);}return n == 1;}private int getNextNumber(int n) {int res = 0;while (n > 0) {int temp = n % 10;res += temp * temp;n = n / 10;}return res;}}
