Leetcode - Arrays | permutations
46. Permutations[M]
https://leetcode.com/problems/permutations/
Description
Given a collection of distinct integers, return all possible permutations.
Example:
1 | Input: [1,2,3] |
Solution
1 |
47. Permutations II[M]
Description
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
Example:
1 | Input: [1,1,2] |
Solution
1 |
31. Next Permutation[M]
https://leetcode.com/problems/next-permutation/
Description
Implement 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 order (ie, sorted in ascending order).
The replacement must be in-place and use only constant extra memory.
Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.
1 | 1,2,3` → `1,3,2` |
Solution
60. Permutation Sequence[H]
https://leetcode.com/problems/permutation-sequence/
Description
The set [1,2,3,...,*n*] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for n = 3:
"123""132""213""231""312""321"
Given n and k, return the kth permutation sequence.
Note:
- Given n will be between 1 and 9 inclusive.
- Given k will be between 1 and n! inclusive.
Example 1:
1 | Input: n = 3, k = 3 |
Example 2:
1 | Input: n = 4, k = 9 |
Solution
1 |
784. Letter Case Permutation[E]
https://leetcode.com/problems/letter-case-permutation/
Description
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create.
1 | Examples: |
Note:
Swill be a string with length between1and12.Swill consist only of letters or digits.
Solution
1 | class Solution: |
567. Permutation in String[M]
https://leetcode.com/problems/permutation-in-string/
Description
iven two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the substring of the second string.
Example 1:
1 | Input: s1 = "ab" s2 = "eidbaooo" |
Example 2:
1 | Input:s1= "ab" s2 = "eidboaoo" |
Constraints:
- The input strings only contain lower case letters.
- The length of both given strings is in range [1, 10,000].
Solution
1 |





