02 2020 档案
摘要:We are given a binary tree (with root node root), a target node, and an integer value K. Return a list of the values of all nodes that have a distance
阅读全文
摘要:Make a deep copy of an undirected graph, there could be cycles in the original graph. Assumptions The given graph is not null DFS /* * class GraphNode
阅读全文
摘要:Each of the nodes in the linked list has another pointer pointing to a random node in the list or null. Make a deep copy of the original list. /** * c
阅读全文
摘要:Given an unsorted integer array, remove adjacent duplicate elements repeatedly, from left to right. For each group of elements with the same value do
阅读全文
摘要:Given a sorted integer array, remove duplicate elements. For each group of elements with the same value do not keep any of them. Do this in-place, usi
阅读全文
摘要:Given a sorted integer array, remove duplicate elements. For each group of elements with the same value keep only one of them. Do this in-place, using
阅读全文
摘要:Given a rope with positive integer-length n, how to cut the rope into m integer-length parts with length p[0], p[1], ...,p[m-1], in order to get the m
阅读全文
摘要:Given an integer n, return all distinct solutions to the n-queens puzzle. Each solution contains a distinct board configuration of the n-queens' place
阅读全文
摘要:Given a binary tree, count the number of nodes in each node’s left subtree, and store it in the numNodesLeft field. Examples 1(6) / \ 2(3) 3(0) / \ 4(
阅读全文
摘要:Given a string, replace adjacent, repeated characters with the character followed by the number of repeated occurrences. Assumptions The string is not
阅读全文
摘要:Given a string in compressed form, decompress it to the original string. The adjacent repeated characters in the original string are compressed to hav
阅读全文
摘要:Given an array of integers that contains only 0s and 1s and a positive integer k, you can flip at most k 0s to 1s, return the longest subarray that co
阅读全文
摘要:Given a string, find the longest substring without any repeating characters and return the length of it. The input string is guaranteed to be not null
阅读全文
摘要:Word “book” can be abbreviated to 4, b3, b2k, etc. Given a string and an abbreviation, return if the string matches the abbreviation. Assumptions: The
阅读全文
摘要:Given an original string input, and two strings S and T, replace all occurrences of S in input with T. Assumptions input, S and T are not null, S is n
阅读全文
摘要:Right shift a given string by n characters. Assumptions The given string is not null. n >= 0. Examples "abc", 4 -> "cab" public class Solution { publi
阅读全文
摘要:Repeatedly remove all adjacent, repeated characters in a given string from left to right. No adjacent characters should be identified in the final str
阅读全文
摘要:Given an array that is initially stored in one stack, sort it with one additional stacks (total 2 stacks). After sorting the original stack should con
阅读全文
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single
阅读全文
摘要:Given a linked list, check whether it is a palindrome. Examples: Input: 1 -> 2 -> 3 -> 2 -> 1 -> null output: true. Input: 1 -> 2 -> 3 -> null output:
阅读全文
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. Example: Input: "25525511135" Output: ["255
阅读全文
摘要:Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example: I
阅读全文
摘要:Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be
阅读全文
摘要:Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not conta
阅读全文
摘要:Given a number of different denominations of coins (e.g., 1 cent, 5 cents, 10 cents, 25 cents), get all the possible ways to pay a target number of ce
阅读全文
摘要:Given N pairs of parentheses “()”, return a list with all the valid permutations. Assumptions N > 0 Examples N = 1, all valid permutations are ["()"]
阅读全文
摘要:Given a string, remove all leading/trailing/duplicated empty spaces. Assumptions: The given string is not null. Examples: “ a” --> “a” “ I love MTV ”
阅读全文
摘要:Given a matrix of size N x M. For each row the elements are sorted in ascending order, and for each column the elements are also sorted in ascending o
阅读全文
摘要:Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twi
阅读全文
摘要:Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input
阅读全文
摘要:Given an array nums sorted in ascending order, return true if and only if you can split it into 1 or more subsequences such that each subsequence cons
阅读全文
摘要:You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a
阅读全文
摘要:Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list
阅读全文
摘要:You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u,v) which consists of one element from th
阅读全文
摘要:Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly on
阅读全文
摘要:You may serialize the following tree: 1 / \ 2 3 / \ 4 5 as "[1,2,3,null,null,4,5]" /** * Definition for a binary tree node. * public class TreeNode {
阅读全文
摘要:Example 1: Input: secret = "1807", guess = "7810" Output: "1A3B" Explanation: 1 bull and 3 cows. The bull is 8, the cows are 0, 1 and 7. Example 2: In
阅读全文
摘要:Let's define a function f(s) over a non-empty string s, which calculates the frequency of the smallest character in s. For example, if s = "dcce" then
阅读全文
摘要:Given an input string, reverse the string word by word. Example 1: Input: "the sky is blue" Output: "blue is sky the" Example 2: Input: " hello world!
阅读全文
摘要:From any string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions). Given two strings source and
阅读全文
摘要:Example: Input: S = "heeellooo" words = ["hello", "hi", "helo"] Output: 1 Explanation: We can extend "e" and "o" in the word "hello" to get "heeellooo
阅读全文
摘要:In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on
阅读全文
摘要:Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1. Example 1: Input: 123 Output: "
阅读全文
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the
阅读全文
摘要:According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John
阅读全文
摘要:There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example to take course 0 you have to
阅读全文
摘要:Design a Tic-tac-toe game that is played between two players on a nx n grid. You may assume the following rules: A move is guaranteed to be valid and
阅读全文
摘要:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longestpath betwee
阅读全文

浙公网安备 33010602011771号