Fork me on GitHub

04 2021 档案

摘要:Construct Binary Tree from Preorder and Inorder Traversal 从前序与中序遍历序列构造二叉树 通过preorder 和inorder,构造一棵二叉树 思路 问题不复杂,有了前序和中序,可以恢复一棵二叉树。 前序里面打头的肯定是root 中序里面的 阅读全文
posted @ 2021-04-28 10:33 WilliamCui 阅读(89) 评论(0) 推荐(0)
摘要:BlockingQueue阻塞队列 A Queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element, and wait for s 阅读全文
posted @ 2021-04-26 10:45 WilliamCui 阅读(91) 评论(0) 推荐(0)
摘要:Path Sum 路径和 给一个二叉树,和sum,判断是否存在一条路径上的节点之和等于sum Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22 Output: true 思路 递归向下求解,直到叶子节点并且 阅读全文
posted @ 2021-04-26 10:42 WilliamCui 阅读(139) 评论(0) 推荐(0)
摘要:Executor Executor Executor 是J.U.C的一个接口,用来处理多线程的。直接说这个可能不太熟,但是大名鼎鼎的ThreadPoolExecutor就是实现了这个接口。 public interface Executor { /** * Executes the given co 阅读全文
posted @ 2021-04-25 09:22 WilliamCui 阅读(131) 评论(0) 推荐(0)
摘要:Balanced Binary Tree 平衡二叉树 给一个二叉树,判断是否为平衡二叉树。 平衡二叉树:一个二叉树*每个节点* 的左右两个子树的高度差的绝对值不超过 1 Input: root = [3,9,20,null,null,15,7] Output: true Input: root = 阅读全文
posted @ 2021-04-23 14:12 WilliamCui 阅读(83) 评论(0) 推荐(0)
摘要:Binary Tree Zigzag Level Order Traversal 二叉树的锯齿形层序遍历 给一个二叉树的root,返回其节点值从上到下遍历,奇数层从左到右 遍历,偶数层从右到左。 Input: root = [3,9,20,null,null,15,7] Output: [[3],[ 阅读全文
posted @ 2021-04-23 09:23 WilliamCui 阅读(88) 评论(0) 推荐(0)
摘要:Binary Tree Level Order Traversal 2 二叉树层序遍历 给一个二叉树的root,返回其节点值从低向上遍历,每一层从左到右 遍历。 Input: root = [3,9,20,null,null,15,7] Output: [[15,7],[9,20],[3]] /** 阅读全文
posted @ 2021-04-22 10:27 WilliamCui 阅读(85) 评论(0) 推荐(0)
摘要:Print Binary Tree Top to Bottom 从上到下打印二叉树 从上到下按层打印二叉树,一层从左到右打印。 思路 使用queue完成对树的层序遍历 /** * Definition for a binary tree node. * public class TreeNode { 阅读全文
posted @ 2021-04-22 10:24 WilliamCui 阅读(88) 评论(0) 推荐(0)
摘要:Invert Binary Tree 翻转二叉树 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() 阅读全文
posted @ 2021-04-21 09:35 WilliamCui 阅读(97) 评论(0) 推荐(0)
摘要:N-ary Tree Preorder Traversal N叉树前序遍历 给一个N叉树的root,返回其前序遍历 输入:root = [1,null,3,2,4,null,5,6] 输出:[1,3,5,6,2,4] /* // Definition for a Node. class Node { 阅读全文
posted @ 2021-04-21 09:30 WilliamCui 阅读(89) 评论(0) 推荐(0)
摘要:Binary Tree Preorder Traversal二叉树的前序遍历 给一个root,返回前序遍历 前序遍历: 根->左->右 递归方法 public void preorder(TreeNode root,List<Integer> res){ if(root == null){ retu 阅读全文
posted @ 2021-04-20 16:56 WilliamCui 阅读(93) 评论(0) 推荐(0)
摘要:Longest Well-Performing Interval 表现良好的最长时间段 We are given hours, a list of the number of hours worked per day for a given employee. A day is considered 阅读全文
posted @ 2021-04-17 11:24 WilliamCui 阅读(127) 评论(0) 推荐(0)
摘要:Exclusive Time of Functions 函数占用时间 在单核单线程CPU上执行任务,任务id 从0到n-1,任务会交替间断执行, Input: n = 2, logs = ["0:start:0","1:start:2","1:end:5","0:end:6"] Output: [3 阅读全文
posted @ 2021-04-16 13:38 WilliamCui 阅读(84) 评论(0) 推荐(0)
摘要:Basic Calculator II 基本计算器 给定一个字符串格式的算式,计算该式的值。只包含+-*/ Input: s = "3+2*2" Output: 7 Input: s = " 3+5 / 2 " Output: 5 思路 使用2个栈,nums存放数字,op存放符号; public i 阅读全文
posted @ 2021-04-16 11:36 WilliamCui 阅读(93) 评论(0) 推荐(0)
摘要:Verify Preorder Serialization of a Binary Tree 验证二叉树前序序列化 前序遍历是啥就不说了,百度一下, 简单说就是root-> left_child->right_child.被前序序列化的二叉树就是一个按照前序遍历的顺序,空节点用#来标识。 该二叉树可 阅读全文
posted @ 2021-04-16 11:21 WilliamCui 阅读(81) 评论(0) 推荐(0)
摘要:Binary Tree Postorder Traversal 二叉树后序遍历 后序遍历是啥就不说了,百度一下, 简单说就是 left_child->right_child->root. Input: root = [1,null,2,3] Output: [3,2,1] 思路 递归处理 /** * 阅读全文
posted @ 2021-04-16 11:19 WilliamCui 阅读(82) 评论(0) 推荐(0)
摘要:Minimum Remove to Make Valid Parentheses 移除无效的括号 给出一个string,其中包含(, ),以及小写字母a~z组成,要求删掉最少的(或),使得剩余的字符串是有效的括号字符串。 Input: s = "a)b(c)d" Output: "ab(c)d" I 阅读全文
posted @ 2021-04-15 09:36 WilliamCui 阅读(95) 评论(0) 推荐(0)
摘要:Remove Outermost Parentheses 删除最外层的括号 Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string i 阅读全文
posted @ 2021-04-15 09:31 WilliamCui 阅读(60) 评论(0) 推荐(0)
摘要:Valid Parentheses 有效的括号 Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. 左括号必须 阅读全文
posted @ 2021-04-14 16:18 WilliamCui 阅读(44) 评论(0) 推荐(0)
摘要:Backspace String Compare 比较含退格的字符串 给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果。 # 代表退格字符。 注意:如果对空文本输入退格字符,文本继续为空。 Input: S = "ab##", T = "c#d#" O 阅读全文
posted @ 2021-04-14 16:16 WilliamCui 阅读(70) 评论(0) 推荐(0)
摘要:Validate Stack Sequence 验证栈序列 Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result o 阅读全文
posted @ 2021-04-14 16:12 WilliamCui 阅读(111) 评论(0) 推荐(0)
摘要:Baseball Game 棒球比赛 比赛开始时,记录是空白的。你会得到一个记录操作的字符串列表 ops,其中 ops[i] 是你需要记录的第 i 项操作,ops 遵循下述规则: 整数 x - 表示本回合新获得分数 x "+" - 表示本回合新获得的得分是前两次得分的总和。题目数据保证记录此操作时前 阅读全文
posted @ 2021-04-14 16:11 WilliamCui 阅读(131) 评论(0) 推荐(0)
摘要:Pancake Sorting 煎饼排序 Given an array of integers arr, sort the array by performing a series of pancake flips. In one pancake flip we do the following s 阅读全文
posted @ 2021-04-11 10:31 WilliamCui 阅读(156) 评论(0) 推荐(0)
摘要:Lemonade Change 任务调度器 At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and order one at a time (in the 阅读全文
posted @ 2021-04-10 10:34 WilliamCui 阅读(93) 评论(0) 推荐(0)
摘要:Buddy Strings 亲密字符串 Given two strings a and b, return true if you can swap two letters in a so the result is equal to b, otherwise, return false. Swap 阅读全文
posted @ 2021-04-10 10:04 WilliamCui 阅读(59) 评论(0) 推荐(0)
摘要:Design Front Middle Back Queue 设计前中后队列 Description Design a queue that supports push and pop operations in the front, middle, and back. Implement the 阅读全文
posted @ 2021-04-10 09:59 WilliamCui 阅读(90) 评论(0) 推荐(0)
摘要:Design Circular Queue 设计循环队列 Description Design your implementation of the circular queue. The circular queue is a linear data structure in which the 阅读全文
posted @ 2021-04-10 09:56 WilliamCui 阅读(98) 评论(0) 推荐(0)
摘要:Task Scheduler 任务调度器 Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks co 阅读全文
posted @ 2021-04-10 09:51 WilliamCui 阅读(236) 评论(0) 推荐(0)
摘要:Design Circular Deque 设计循环双端队列 Description Design your implementation of the circular double-ended queue (deque). Your implementation should support f 阅读全文
posted @ 2021-04-01 10:42 WilliamCui 阅读(96) 评论(0) 推荐(0)