220. Contains Duplicate III

2019-02-21
阅读 2 分钟
1.5k
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute difference between i and j is at most k.Example 1:

219. Contains Duplicate II

2019-02-21
阅读 1 分钟
1.7k
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.

217. Contains Duplicate

2019-02-21
阅读 1 分钟
1.3k
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.Example 1:

221. Maximal Square

2019-02-21
阅读 2 分钟
1.5k
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

222. Count Complete Tree Nodes

2019-02-20
阅读 1 分钟
1.4k
Note:Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

216. Combination Sum III

2019-02-20
阅读 2 分钟
1.9k
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 a unique set of numbers.

215. Kth Largest Element in an Array

2019-02-20
阅读 2 分钟
1.3k
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.

409. Longest Palindrome

2019-02-20
阅读 1 分钟
1.2k
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not considered a palindrome here.Note:Assume the length of given string will not exceed 1,010.

142. Linked List Cycle II

2019-02-19
阅读 3 分钟
1.4k
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the link...

113. Path Sum II

2019-02-17
阅读 2 分钟
1.2k
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.

103. Binary Tree Zigzag Level Order Traversal

2019-02-17
阅读 2 分钟
1.1k
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).

95. Unique Binary Search Trees II

2019-02-17
阅读 2 分钟
1.4k
Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n.

96. Unique Binary Search Trees

2019-02-17
阅读 1 分钟
1k
Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?

98. Validate Binary Search Tree

2019-02-17
阅读 2 分钟
1.3k
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The right subtree of a node contains only nodes with keys greater than the node's key.Both the left and rig...

114. Flatten Binary Tree to Linked List

2019-02-17
阅读 2 分钟
1.3k
Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: {代码...} The flattened tree should look like: {代码...} 难度:medium 题目:给定二叉树,原地扁平化。 思路:后序遍历 Runtime: 6 ms, faster than 100.00% of Java online submissions for Flatten Binary Tr...

116. Populating Next Right Pointers in Each Node

2019-02-17
阅读 3 分钟
1.2k
You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:

117. Populating Next Right Pointers in Each Node II

2019-02-17
阅读 3 分钟
2.2k
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

131. Palindrome Partitioning

2019-02-17
阅读 2 分钟
1.3k
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.Example:

120. Triangle

2019-02-16
阅读 2 分钟
1.3k
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.

129. Sum Root to Leaf Numbers

2019-02-16
阅读 2 分钟
1.3k
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.

130. Surrounded Regions

2019-02-16
阅读 2 分钟
1.1k
Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.Example:

138. Copy List with Random Pointer

2019-02-16
阅读 2 分钟
1.4k
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.

102. Binary Tree Level Order Traversal

2019-02-16
阅读 2 分钟
1.8k
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

143. Reorder List

2019-02-16
阅读 2 分钟
831
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…

148. Sort List

2019-02-16
阅读 2 分钟
1.2k
Sort a linked list in O(n log n) time using constant space complexity.

144. Binary Tree Preorder Traversal

2019-02-16
阅读 1 分钟
1.5k
Given a binary tree, return the preorder traversal of its nodes' values.

147. Insertion Sort List

2019-02-15
阅读 2 分钟
1.1k
Sort a linked list using insertion sort.A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration one element (red) is removed from the input data and inserted in-place into the sorted list

150. Evaluate Reverse Polish Notation

2019-02-15
阅读 2 分钟
1.3k
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Note:Division between two integers should truncate toward zero.The given RPN expression is always valid. That means the expression would a...

151. Reverse Words in a String

2019-02-15
阅读 2 分钟
1.6k
Given an input string, reverse the string word by word.Example: {代码...} Note: {代码...} Follow up: For C programmers, try to solve it in-place in O(1) space. 难度:medium 题目:给定字符串,反转字符串中的单词。注意:单词指一组非空字符。输入的字符串可能包含前后空格。你需要在两个单词之间只保留一个...

991. Broken Calculator

2019-02-15
阅读 2 分钟
1.6k
On a broken calculator that has a number showing on its display, we can perform two operations:Double: Multiply the number on the display by 2, or;Decrement: Subtract 1 from the number on the display.Initially, the calculator is displaying the number X.