10 2022 档案

摘要:今天还是二叉树 654. 最大二叉树 class Solution { public TreeNode constructMaximumBinaryTree(int[] nums) { int n = nums.length; return maxTree(nums, 0, n - 1); } pu 阅读全文
posted @ 2022-10-31 15:24 小猫Soda 阅读(15) 评论(0) 推荐(0) 编辑
摘要:今天是本周二叉树的最后一章了,内容都是偏难的 513.找树左下角的值 class Solution { public int findBottomLeftValue(TreeNode root) { Queue<TreeNode> q = new LinkedList<>(); q.offer(ro 阅读全文
posted @ 2022-10-30 11:50 小猫Soda 阅读(19) 评论(0) 推荐(0) 编辑
摘要:今天继续二叉树的学习 110. 平衡二叉树 class Solution { public boolean isBalanced(TreeNode root) { return dfs(root)>=0; } public int dfs(TreeNode root){ if(root == nul 阅读全文
posted @ 2022-10-29 14:33 小猫Soda 阅读(16) 评论(0) 推荐(0) 编辑
摘要:今天是第十六天,继续二叉树方面的递归练习 104. 二叉树的最大深度 class Solution { public int maxDepth(TreeNode root) { if(root == null){ return 0; } else{ return Math.max(maxDepth( 阅读全文
posted @ 2022-10-28 14:11 小猫Soda 阅读(16) 评论(0) 推荐(0) 编辑
摘要:今天是训练营的第十五天,继续二叉树方面的学习 迭代法遍历: 前序: class Solution { public List<Integer> preorderTraversal(TreeNode root) { Stack<TreeNode> s = new Stack<>(); List<Int 阅读全文
posted @ 2022-10-27 10:12 小猫Soda 阅读(14) 评论(0) 推荐(0) 编辑
摘要:今天是第十四天,除了二叉树的基本概念外,还有递归法的应用 144. 二叉树的前序遍历 class Solution { public List<Integer> preorderTraversal(TreeNode root) { List<Integer> res = new ArrayList< 阅读全文
posted @ 2022-10-26 02:01 小猫Soda 阅读(15) 评论(0) 推荐(0) 编辑
摘要:今天是第十三天,是队列相关,难度不小 239. 滑动窗口最大值 class Solution { public int[] maxSlidingWindow(int[] nums, int k) { int n = nums.length; if(n<2){ return nums; } Deque 阅读全文
posted @ 2022-10-24 14:13 小猫Soda 阅读(19) 评论(0) 推荐(0) 编辑
摘要:今天是第十一天,继续更深入的学习栈和队列 20. 有效的括号 class Solution { public boolean isValid(String s) { Stack<Character> stack = new Stack<Character>(); for(char c: s.toCh 阅读全文
posted @ 2022-10-22 12:04 小猫Soda 阅读(14) 评论(0) 推荐(0) 编辑
摘要:第十天 今天开始学习stack相关 232. 用栈实现队列 class MyQueue { Stack<Integer> in; Stack<Integer> out; public MyQueue() { in = new Stack<>(); out = new Stack<>(); } pub 阅读全文
posted @ 2022-10-21 11:24 小猫Soda 阅读(17) 评论(0) 推荐(0) 编辑
摘要:第八天,从昨天看,难度应该会递加,今天是五道题,稍有挑战性了。 344. 反转字符串 class Solution { public void reverseString(char[] s) { int n = s.length; int i = 0; int j = n - 1; while(i< 阅读全文
posted @ 2022-10-19 14:07 小猫Soda 阅读(17) 评论(0) 推荐(0) 编辑
摘要:今天是第七天 内容依旧是HashMap相关 454. 四数相加2 class Solution { public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) { Map<Integer, Integer> 阅读全文
posted @ 2022-10-18 14:47 小猫Soda 阅读(18) 评论(0) 推荐(0) 编辑
摘要:休息日结束后的第一天 242. 有效的字母异位词 class Solution { public boolean isAnagram(String s, String t) { HashMap<Character,Integer> map = new HashMap<>(); if(s.length 阅读全文
posted @ 2022-10-17 15:29 小猫Soda 阅读(16) 评论(0) 推荐(0) 编辑
摘要:今天是第四天,今天的内容依旧延续昨天的课题,链表 24. 两两交换链表中的节点 class Solution { public ListNode swapPairs(ListNode head) { if(head == null || head.next == null){ return head 阅读全文
posted @ 2022-10-15 14:51 小猫Soda 阅读(15) 评论(0) 推荐(0) 编辑
摘要:第三天是链表,要注意的是可以创建虚拟头节点来进行链表操作。 203. 移除链表元素 class Solution { public ListNode removeElements(ListNode head, int val) { ListNode temp = new ListNode(-1); 阅读全文
posted @ 2022-10-14 04:28 小猫Soda 阅读(29) 评论(0) 推荐(0) 编辑
摘要:今天是训练营第二天,包含了第一天双指针的扩展题 977. 有序数组的平方 class Solution { public int[] sortedSquares(int[] nums) { int n = nums.length; int[] res = new int[n]; int l = 0; 阅读全文
posted @ 2022-10-13 14:54 小猫Soda 阅读(34) 评论(0) 推荐(0) 编辑
摘要:算法训练营第一天,训练内容是二分查找和双指针。 704. 二分查找 ``` class Solution { public int search(int[] nums, int target) { int n = nums.length; int l = 0; int r = n; while(l< 阅读全文
posted @ 2022-10-12 13:55 小猫Soda 阅读(45) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示