随笔分类 - Level 2
摘要:Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1, and return them in any ord
阅读全文
摘要:Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that ca
阅读全文
摘要:You are given some lists of regions where the first region of each list includes all other regions in that list. Naturally, if a region X contains ano
阅读全文
摘要:Problem description: Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the
阅读全文
摘要:Given a list accounts, each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements a
阅读全文
摘要:Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Input: [0,1] Output: 2 Explanation: [0
阅读全文
摘要:Given the root of a binary tree, find the maximum value V for which there exists different nodes A and B where V = |A.val - B.val| and A is an ancesto
阅读全文
摘要:Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[
阅读全文
摘要:There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct
阅读全文
摘要:Given a rooted binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only if i
阅读全文
摘要:You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1'
阅读全文
摘要:Given a string s and an integer k, find out if the given string is a K-Palindrome or not. A string is K-Palindrome if it can be transformed into a pal
阅读全文
摘要:Given a matrix, like this[[0, 0, 1, 1, 1][0, 1, 1, 1, 1][0, 0, 1, 1, 1][0, 0, 0, 0, 0]]each cell is either 1 or 0in each row, from left to right, when
阅读全文
摘要:给两个bst,把它们的值按照从小到大打印。 1 public static void print2BSTInorder(TreeNode n1, TreeNode n2, List<Integer> result) { 2 Stack<TreeNode> stack1 = new Stack<>()
阅读全文
摘要:byte swap一个 32位数 0x12345678 --> 0x78563412先是用了俩高低位mask 两两交换,不满意。然后用了一个mask,每次取一个byte,移位异或ans。一共执行四次,还是不满意。提示说用两步,能不能先交换 LSB 和 MSB,写了一下,但还是想不出怎么写。。。正解:
阅读全文
摘要:Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any position
阅读全文
摘要:给两个已经排序好的数组A,B,和一个常数k, 找i,j使得 Ai + Bj - k 的绝对值最小 分析: Two pointer, i从A从前往后扫,j从B从后往前扫.if (A[i]+B[j] > k){ j--;}else { i++;}整个过程不断更新答案
阅读全文
摘要:有个N叉树是个大食堂的地图。节点有的是餐馆,有的不是,在输入里面用boolean表示了。每个父节点到子节点的距离都是一。你作为一个吃货,从根节点出发,要去所有的餐馆尝尝,需要的最短路径是多少。楼主DFS返回两个量,一个是这个节点为根的树要吃完需要的走多长的路,另一个是一个flag表示这个子树里面有没
阅读全文
摘要:Given a binary tree rooted at root, the depth of each node is the shortest distance to the root. A node is deepest if it has the largest depth possibl
阅读全文
摘要:Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image. Example: Input:
阅读全文

浙公网安备 33010602011771号