498. Diagonal Traverse
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. Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output:...
View Article496 Next Greater Element 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's elements in the corresponding places of nums2....
View ArticleGit for Beginner
How to upload your code to git server? After installing git, execute these in command line: git config --global user.name "Your Name" git config --global user.email "email@example.com *******...
View ArticleWord Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, given s =...
View ArticleInsert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example...
View ArticleMerge Intervals
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]....
View ArticleMerge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Merge...
View ArticleMultiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 计算两个大数的乘法,如果直接计算,就会溢出。假设两个数的长度分别为m,...
View ArticleN-Queens II
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. 同样是N皇后的问题,要求我们输出有几种结果,思路同N-Queens是一样的,这里就不在赘述了,代码如下: public class Solution...
View ArticleN-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. Each...
View ArticleCount and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2,...
View ArticleValid Sudoku 数独
Determine if a Sudoku is valid. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially filled sudoku which is valid. Note: A valid Sudoku board...
View ArticleSearch Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array....
View ArticleSearch for a Range
Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the...
View ArticleSearch in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return its...
View ArticleNext Permutation 全排列
mplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible...
View ArticleDivide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 题目要求我们不用乘法,除法还有模运算来完成两个整数的除运算。如果溢出时返回最大值。...
View ArticleRemove Element
Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length....
View ArticleRemove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with...
View ArticleImplement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack....
View Article