Given a binary tree, return the level order traversal of its nodes'values. (ie, from left to right, level by level).For example: Given binary tree [3,9,20,null,null,15,7],return its level order traversal as: [ [3], [9,20], [15,7] ]
Given a collection of distinct integers, return all possiblepermutations.Example: Input: [1,2,3] Output: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]
Given a set of distinct integers, nums, return all possible subsets(the power set).Note: The solution set must not contain duplicate subsets. Example: Input: nums = [1,2,3] Output: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
A linked list is given such that each node contains an additionalrandom pointer which could point to any node in the list or null.Return a deep copy of the list.
any single node in the list, and may not be necessarily the smallestvalue in the cyclic list.If there are multiple suitable places for insertion, you may chooseany place to insert the new value. After the insertion, the cycliclist should remain sorted. If the list is empty (i.e., given node is nu...
Given a singly linked list, group all odd nodes together followed bythe even nodes. Please note here we are talking about the node numberand not the value in the nodes.You should try to do it in place. The program should run in O(1) spacecomplexity and O(nodes) time complexity. Example 1: Input: ...
Write a program to find the node at which the intersection of twosingly linked lists begins. For example, the following two linked lists: A: a1 → a2 {代码...} Notes: If the two linked lists have no intersection at all, return null. Thelinked lists must retain their original structure after the fu...
Given an array of n positive integers and a positive integer s, findthe minimal length of a contiguous subarray of which the sum ≥ s. Ifthere isn't one, return 0 instead.Example: Input: s = 7, nums = [2,3,1,2,4,3] Output: 2 Explanation: the subarray[4,3] has the minimal length under the problem c...
Given a binary array, find the maximum number of consecutive 1s inthis array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first twodigits or the last three digits are consecutive 1s. {代码...} The input array will only contain 0 and 1. The length of input arrayis a positive integer...
Given an array nums and a value val, remove all instances of thatvalue in-place and return the new length.Do not allocate extra space for another array, you must do this bymodifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you l...
Write a function that takes a string as input and returns the stringreversed.Example 1: Input: "hello" Output: "olleh" Example 2: Input: "A man, a plan, a canal: Panama" Output: "amanaP :lanac a ,nalpa ,nam A"
Given a matrix of m x n elements (m rows, n columns), return allelements of the matrix in spiral order.Example 1: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output:[1,2,3,6,9,8,7,4,5] Example 2: Input: [ [1, 2, 3, 4], [5, 6, 7, 8], [9,10,11,12] ] Output:[1,2,3,4,8,12,11,10,9,5,6,7]
Given a matrix of M x N elements (M rows, N columns), return allelements of the matrix in diagonal order as shown in the below image.Example: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,4,7,5,3,6,8,9] Explanation: Note: The total number of elements of the given matrix will not e...
Given a non-empty array of digits representing a non-negative integer,plus one to the integer. The digits are stored such that the most significant digit is at thehead of the list, and each element in the array contain a singledigit. You may assume the integer does not contain any leading zero, e...
In a given integer array nums, there is always exactly one largestelement. Find whether the largest element in the array is at least twice asmuch as every other number in the array. If it is, return the index of the largest element, otherwise return-1. Note: nums will have a length in the range [...
Determine if a Sudoku is valid, according to: Sudoku Puzzles - TheRules. The Sudoku board could be partially filled, where empty cells arefilled with the character '.'.
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacentcell, where "adjacent" cells are those horizontally or verticallyneighboring. The same letter cell may not be used more than once. For example, Given board = {代码......
The n-queens puzzle is the problem of placing n queens on an n×nchessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queenspuzzle. Each solution contains a distinct board configuration of the n-queens'placement, where 'Q' and '.' both ind...
Given a string s, partition s such that every substring of thepartition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab", Return [ {代码...}
Given a string containing only digits, restore it by returning allpossible valid IP address combinations. For example: Given "25525511135", return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)
Given a collection of distinct numbers, return all possiblepermutations. For example, [1,2,3] have the following permutations: [1,2,3],[1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
Given a set of candidate numbers (C) and a target number (T), find allunique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited number oftimes. Note: All numbers (including target) will be positive integers.Elements in a combination (a...