2022年10月26日

map hashmap api

摘要: ###接口:java.util.Map<K, V> ###实现: java.util.HashMap<K, V>:哈希表 java.util.TreeMap<K, V>:平衡树 ###getOrDefault map.getOrDefault("key", default)//如果map里有key就 阅读全文

posted @ 2022-10-26 21:49 你是千堆雪我是长街7 阅读(30) 评论(0) 推荐(0)

2022年10月24日

day34 1005

摘要: ###1005. K 次取反后最大化的数组和 class Solution { public int largestSumAfterKNegations(int[] nums, int k) { Arrays.sort(nums); int i=0; while(k>0&&i<nums.length 阅读全文

posted @ 2022-10-24 21:17 你是千堆雪我是长街7 阅读(9) 评论(0) 推荐(0)

2022年10月23日

贪心算法 455

摘要: ###455. 分发饼干 class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); //孩子列表 Arrays.sort(s); //饼干列表 int start=0; //先把饼干和孩子从 阅读全文

posted @ 2022-10-23 13:24 你是千堆雪我是长街7 阅读(9) 评论(0) 推荐(0)

2022年10月16日

day24 77

摘要: 回溯算法 数字组合问题 ###77. 组合 class Solution { List<List<Integer>> result = new ArrayList<>(); LinkedList<Integer> path = new LinkedList<>(); public List<List 阅读全文

posted @ 2022-10-16 21:53 你是千堆雪我是长街7 阅读(20) 评论(0) 推荐(0)

2022年10月13日

day23 669 108 538

摘要: ###669. 修剪二叉搜索树 class Solution { public TreeNode trimBST(TreeNode root, int low, int high) { if(root==null) return null; if(root.val>high){ //比high还大 阅读全文

posted @ 2022-10-13 21:03 你是千堆雪我是长街7 阅读(11) 评论(0) 推荐(0)

2022年10月11日

day21

摘要: ###501. 二叉搜索树中的众数 class Solution { List<Integer> result=new ArrayList<Integer>(); int base,count,maxCount; //用base来存当前的众数值,count存放当前众数的个数,maxCount存放已经 阅读全文

posted @ 2022-10-11 22:44 你是千堆雪我是长街7 阅读(12) 评论(0) 推荐(0)

2022年10月10日

day20 700,617,98, 645

摘要: ###700. 二叉搜索树中的搜索 class Solution { public TreeNode searchBST(TreeNode root, int val) { if(root.val==val||root==null) return root; //1:终止条件 if(root.val 阅读全文

posted @ 2022-10-10 21:31 你是千堆雪我是长街7 阅读(32) 评论(0) 推荐(0)

2022年10月8日

day16 104,222

摘要: ###104. 二叉树的最大深度 class Solution { //层序遍历 public int maxDepth(TreeNode root) { if(root==null){ return 0; } Queue<TreeNode> que=new LinkedList<>(); que. 阅读全文

posted @ 2022-10-08 11:39 你是千堆雪我是长街7 阅读(10) 评论(0) 推荐(0)

day17 110

摘要: ###110平衡二叉树 class Solution { public boolean isBalanced(TreeNode root) { return (getHeight(root)!=-1); //返回值是一个int 类型 左右子树的最大高度 } public int getHeight( 阅读全文

posted @ 2022-10-08 11:14 你是千堆雪我是长街7 阅读(9) 评论(0) 推荐(0)

2022年10月5日

day15

摘要: ###二叉树的层序遍历 模板 //利用一个指针来记录每一层的节点的数量(很关键) class Solution { public List<Integer> rightSideView(TreeNode root) { List<Integer> reslist=new ArrayList<Inte 阅读全文

posted @ 2022-10-05 22:27 你是千堆雪我是长街7 阅读(18) 评论(0) 推荐(0)

导航