289. Game of Life

Problem description:

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 Horton Conway in 1970.”

Readmore

31. Next Permutation

Problem description:

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.

Readmore

73. Set Matrix Zeroes

Problem description:

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Example 1:

Input:
[
[1,1,1],
[1,0,1],
[1,1,1]
]
Output:
[
[1,0,1],
[0,0,0],
[1,0,1]
]

Readmore

79. Word Search

Problem description:

Given a 2D board and a word, find if the word exists in the grid.

Readmore

287. Find the Duplicate Number

Problem description:

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.

1
2
3
4
Example 1:

Input: [1,3,4,2,2]
Output: 2

Readmore

228. Summary Ranges

Problem description:
/*
Given a sorted integer array without duplicates, return the summary of its ranges.

1
2
3
4
5
Example 1:

Input: [0,1,2,4,5,7]
Output: ["0->2","4->5","7"]
Explanation: 0,1,2 form a continuous range; 4,5 form a continuous range.

Readmore

229. Majority Element II

Problem description:

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.

Note: The algorithm should run in linear time and in O(1) space.

Readmore

59. Spiral Matrix II

Problem description:

Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.

1
2
3
4
5
6
7
8
9
Example:

Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]

Readmore

54. Spiral Matrix

Problem description:

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.

1
2
3
4
5
6
7
8
9
Example 1:

Input:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
Output: [1,2,3,6,9,8,7,4,5]

Readmore

16. 3Sum Closest

Problem description:
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.

Readmore