0%

Description

Given a collection of numbers that might contain duplicates, return all possible unique permutations.

Example:

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

Difficulty: Medium

Code:

1
2
3
4
5
class Solution {
public List<List<Integer>> permuteUnique(int[] nums) {

}
}

题意

给定一组可能包含重复数字的集合,返回所以不重复的全排列。

阅读全文 »

Description

Given a collection of distinct integers, return all possible permutations.

Example:

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

Difficulty: Medium

Code:

1
2
3
4
5
class Solution {
public List<List<Integer>> permute(int[] nums) {

}
}

题意

给定一系列非重复数字,返回全排列。

阅读全文 »

Description

Given an array of non-negative integers, you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Your goal is to reach the last index in the minimum number of jumps.

Example:

1
2
3
4
Input: [2,3,1,1,4]
Output: 2
Explanation: The minimum number of jumps to reach the last index is 2.
Jump 1 step from index 0 to 1, then 3 steps to the last index.

Note:

You can assume that you can always reach the last index.

Difficulty: Hard

Code:

1
2
3
4
5
class Solution {
public int jump(int[] nums) {

}
}

题意

给定一个正数数组,初始化时指向数组的第一个元素,每个元素的值表示在这个位置上能向前跳的最大长度。

目标是跳动到最后一个元素,并且用到步数最少,并返回最少步数。假定一定能够到达最后一个元素。

阅读全文 »

Description

Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for ‘?’ and ‘*’.

1
2
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).

The matching should cover the entire input string (not partial).

Note:

  • s could be empty and contains only lowercase letters a-z.
  • p could be empty and contains only lowercase letters a-z, and characters like ? or *.

Example 1:

1
2
3
4
5
Input:
s = "aa"
p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".

Example 2:

1
2
3
4
5
Input:
s = "aa"
p = "*"
Output: true
Explanation: '*' matches any sequence.

Example 3:

1
2
3
4
5
Input:
s = "cb"
p = "?a"
Output: false
Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.

Example 4:

1
2
3
4
5
Input:
s = "adceb"
p = "*a*b"
Output: true
Explanation: The first '*' matches the empty sequence, while the second '*' matches the substring "dce".

Example 5:

1
2
3
4
Input:
s = "acdcb"
p = "a*c?b"
Output: false

Difficulty: Hard

Code:

1
2
3
4
5
class Solution {
public boolean isMatch(String s, String p) {

}
}

题意

给定一个字符串s和模式p,实现通配符匹配,支持?和。?表示任意一个字符,表示任何字符串。

匹配是完全匹配,s可能为空或者只包含a-z,p可能为空或者包含a-z和?或*。

阅读全文 »

Description

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.

Example 1:

1
2
Input: num1 = "2", num2 = "3"
Output: "6"

Example 2:

1
2
Input: num1 = "123", num2 = "456"
Output: "56088"

Note:

  1. The length of both num1 and num2 is < 110.
  2. Both num1 and num2 contain only digits 0-9.
  3. Both num1 and num2 do not contain any leading zero, except the number 0 itself.
  4. You must not use any built-in BigInteger library or convert the inputs to integer directly.

Difficulty: Medium

Code:

1
2
3
4
5
class Solution {
public String multiply(String num1, String num2) {

}
}

题意

给定两个代表非负num1和num2的字符串,用字符串表示它们的乘积。字符串的长度小于110,只包含0-9。不能将输入转成int进行计算。

阅读全文 »