Description
Difficulty: Simple
请实现一个函数,把字符串
s
中的每个空格替换成”%20”。示例 :
输入:s = “We are happy.”
输出:”We%20are%20happy.”
Difficulty: Simple
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
- Integers in each row are sorted in ascending from left to right.
- Integers in each column are sorted in ascending from top to bottom.
Example:
Consider the following matrix:
1
2
3
4
5
6
7 [
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]Given target =
5
, returntrue
.Given target =
20
, returnfalse
.
Difficulty: Medium
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.
Example:
Input: [1,3,4,2,2]
Output: 2
Note:
- You must not modify the array (assume the array is read only).
- You must use only constant, O(1) extra space.
- Your runtime complexity should be less than O(n^2).
- There is only one duplicate number in the array, but it could be repeated more than once.