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
14Example 1:
Input:
[
[1,1,1],
[1,0,1],
[1,1,1]
]
Output:
[
[1,0,1],
[0,0,0],
[1,0,1]
]
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
4Example 1:
Input: [1,3,4,2,2]
Output: 2
Problem description:
/*
Given a sorted integer array without duplicates, return the summary of its ranges.1
2
3
4
5Example 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.
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.
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
9Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]
Problem description:
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
1 | Example 1: |
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.