摘要: 1.leetcode455 分发饼干 这里的局部最优解其实就是:大饼干先满足大胃口的 class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int con 阅读全文
posted @ 2022-05-13 19:53 明卿册 阅读(49) 评论(0) 推荐(0) 编辑
摘要: 该笔记刷算法题(leetcode、洛谷、蓝桥杯)中遇到常见的小语法进行整理: int与char互转 int num = 9; char c = (char)num; char ch = '9'; num = (int)ch-'0'; 逆序排列 int[] arr = {1,2,3,4,5}; Arr 阅读全文
posted @ 2022-05-12 17:42 明卿册 阅读(104) 评论(0) 推荐(0) 编辑
摘要: ##leetcode51 八皇后问题 皇后会对同一行、同一列、同一左斜对角线、同一右斜对角线的皇后发起攻击。 使用point数组来记录每个皇后放置的位置,使用canUse来确定该行哪个位置能放置皇后。 现在有两个皇后,其坐标分别为(x1,y1),(x2,y2) 同一左斜对角线的数学规律:x1-y1 阅读全文
posted @ 2022-05-12 15:14 明卿册 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 4.2 AOF AOF默认是关闭的,需要在配置文件中开启AOF。Redis支持AOF和RDB同时生效。如果同时存在,AOF优先级高于RDB(redis重新启动时会使用AOF进行数据恢复) RDB记录的是紧凑的数据,AOF记录的是命令。 把配置文件中的appendonly从no改成yes 每秒钟记录一 阅读全文
posted @ 2022-04-29 14:39 明卿册 阅读(27) 评论(0) 推荐(0) 编辑
摘要: 回溯中最需要注意的问题是——对于深度的控制是万万不能写成循环的形式的。应该是在对宽度进行遍历的时候+1,然后在回溯函数开头进行控制。 private void backtracking(String digits, int idx) { if(idx == digits.length()) { // 阅读全文
posted @ 2022-04-20 10:57 明卿册 阅读(17) 评论(0) 推荐(0) 编辑
摘要: class Solution { private List<List<Integer>> ans = new ArrayList(); private List<Integer> list = new ArrayList(); private void backtracking(int k, int 阅读全文
posted @ 2022-04-20 08:32 明卿册 阅读(17) 评论(0) 推荐(0) 编辑
摘要: 我一开始的写法: class Solution { private List<List<Integer>> ans = new ArrayList(); private List<Integer> list = new ArrayList(); private void backtracking(i 阅读全文
posted @ 2022-04-19 13:58 明卿册 阅读(25) 评论(0) 推荐(0) 编辑
摘要: 这个东西本质上就是一个搜索+存储,只要把遍历的每一个val存下来就行了。 你能意识到这个东西是对右子树的中序遍历,如果实在不知道怎么写就先写注释。 而且也不一定非要一口气写成一个唯一函数,熟能生巧熟能生巧,先熟再巧。 class Solution { private int num = 0; pub 阅读全文
posted @ 2022-04-19 11:56 明卿册 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 二叉树的题目无脑递归做,关键还是在三板斧——确定参数和返回值、终止条件和单层逻辑体 public TreeNode trimBST(TreeNode root, int low, int high) { if(root == null) return null; if(root.val < low) 阅读全文
posted @ 2022-04-18 11:49 明卿册 阅读(33) 评论(0) 推荐(0) 编辑
摘要: 最难的就是要理解,通过递归函数返回值完成了新加入节点的父子关系赋值操作 class Solution { public TreeNode insertIntoBST(TreeNode root, int val) { if(root == null) { TreeNode node = new Tr 阅读全文
posted @ 2022-03-06 17:22 明卿册 阅读(16) 评论(0) 推荐(0) 编辑