-
Notifications
You must be signed in to change notification settings - Fork 93
Added descriptions 31-40. #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
src/main/java/g0001_0100/s0031_next_permutation/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
31\. Next Permutation | ||
|
||
Medium | ||
|
||
Implement **next permutation**, which rearranges numbers into the lexicographically next greater permutation of numbers. | ||
|
||
If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order). | ||
|
||
The replacement must be **[in place](http://en.wikipedia.org/wiki/In-place_algorithm)** and use only constant extra memory. | ||
|
||
**Example 1:** | ||
|
||
**Input:** nums = \[1,2,3\] | ||
|
||
**Output:** \[1,3,2\] | ||
|
||
**Example 2:** | ||
|
||
**Input:** nums = \[3,2,1\] | ||
|
||
**Output:** \[1,2,3\] | ||
|
||
**Example 3:** | ||
|
||
**Input:** nums = \[1,1,5\] | ||
|
||
**Output:** \[1,5,1\] | ||
|
||
**Example 4:** | ||
|
||
**Input:** nums = \[1\] | ||
|
||
**Output:** \[1\] | ||
|
||
**Constraints:** | ||
|
||
* `1 <= nums.length <= 100` | ||
* `0 <= nums[i] <= 100` |
32 changes: 32 additions & 0 deletions
src/main/java/g0001_0100/s0032_longest_valid_parentheses/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
32\. Longest Valid Parentheses | ||
|
||
Hard | ||
|
||
Given a string containing just the characters `'('` and `')'`, find the length of the longest valid (well-formed) parentheses substring. | ||
|
||
**Example 1:** | ||
|
||
**Input:** s = "(()" | ||
|
||
**Output:** 2 | ||
|
||
**Explanation:** The longest valid parentheses substring is "()". | ||
|
||
**Example 2:** | ||
|
||
**Input:** s = ")()())" | ||
|
||
**Output:** 4 | ||
|
||
**Explanation:** The longest valid parentheses substring is "()()". | ||
|
||
**Example 3:** | ||
|
||
**Input:** s = "" | ||
|
||
**Output:** 0 | ||
|
||
**Constraints:** | ||
|
||
* `0 <= s.length <= 3 * 104` | ||
* `s[i]` is `'('`, or `')'`. |
37 changes: 37 additions & 0 deletions
src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
33\. Search in Rotated Sorted Array | ||
|
||
Medium | ||
|
||
There is an integer array `nums` sorted in ascending order (with **distinct** values). | ||
|
||
Prior to being passed to your function, `nums` is **possibly rotated** at an unknown pivot index `k` (`1 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (**0-indexed**). For example, `[0,1,2,4,5,6,7]` might be rotated at pivot index `3` and become `[4,5,6,7,0,1,2]`. | ||
|
||
Given the array `nums` **after** the possible rotation and an integer `target`, return _the index of_ `target` _if it is in_ `nums`_, or_ `-1` _if it is not in_ `nums`. | ||
|
||
You must write an algorithm with `O(log n)` runtime complexity. | ||
|
||
**Example 1:** | ||
|
||
**Input:** nums = \[4,5,6,7,0,1,2\], target = 0 | ||
|
||
**Output:** 4 | ||
|
||
**Example 2:** | ||
|
||
**Input:** nums = \[4,5,6,7,0,1,2\], target = 3 | ||
|
||
**Output:** -1 | ||
|
||
**Example 3:** | ||
|
||
**Input:** nums = \[1\], target = 0 | ||
|
||
**Output:** -1 | ||
|
||
**Constraints:** | ||
|
||
* `1 <= nums.length <= 5000` | ||
* `-104 <= nums[i] <= 104` | ||
* All values of `nums` are **unique**. | ||
* `nums` is an ascending array that is possibly rotated. | ||
* `-104 <= target <= 104` |
34 changes: 34 additions & 0 deletions
...01_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
34\. Find First and Last Position of Element in Sorted Array | ||
|
||
Medium | ||
|
||
Given an array of integers `nums` sorted in non-decreasing order, find the starting and ending position of a given `target` value. | ||
|
||
If `target` is not found in the array, return `[-1, -1]`. | ||
|
||
You must write an algorithm with `O(log n)` runtime complexity. | ||
|
||
**Example 1:** | ||
|
||
**Input:** nums = \[5,7,7,8,8,10\], target = 8 | ||
|
||
**Output:** \[3,4\] | ||
|
||
**Example 2:** | ||
|
||
**Input:** nums = \[5,7,7,8,8,10\], target = 6 | ||
|
||
**Output:** \[-1,-1\] | ||
|
||
**Example 3:** | ||
|
||
**Input:** nums = \[\], target = 0 | ||
|
||
**Output:** \[-1,-1\] | ||
|
||
**Constraints:** | ||
|
||
* `0 <= nums.length <= 105` | ||
* `-109 <= nums[i] <= 109` | ||
* `nums` is a non-decreasing array. | ||
* `-109 <= target <= 109` |
44 changes: 44 additions & 0 deletions
src/main/java/g0001_0100/s0035_search_insert_position/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
35\. Search Insert Position | ||
|
||
Easy | ||
|
||
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. | ||
|
||
You must write an algorithm with `O(log n)` runtime complexity. | ||
|
||
**Example 1:** | ||
|
||
**Input:** nums = \[1,3,5,6\], target = 5 | ||
|
||
**Output:** 2 | ||
|
||
**Example 2:** | ||
|
||
**Input:** nums = \[1,3,5,6\], target = 2 | ||
|
||
**Output:** 1 | ||
|
||
**Example 3:** | ||
|
||
**Input:** nums = \[1,3,5,6\], target = 7 | ||
|
||
**Output:** 4 | ||
|
||
**Example 4:** | ||
|
||
**Input:** nums = \[1,3,5,6\], target = 0 | ||
|
||
**Output:** 0 | ||
|
||
**Example 5:** | ||
|
||
**Input:** nums = \[1\], target = 0 | ||
|
||
**Output:** 0 | ||
|
||
**Constraints:** | ||
|
||
* `1 <= nums.length <= 104` | ||
* `-104 <= nums[i] <= 104` | ||
* `nums` contains **distinct** values sorted in **ascending** order. | ||
* `-104 <= target <= 104` |
58 changes: 58 additions & 0 deletions
src/main/java/g0001_0100/s0036_valid_sudoku/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
36\. Valid Sudoku | ||
|
||
Medium | ||
|
||
Determine if a `9 x 9` Sudoku board is valid. Only the filled cells need to be validated **according to the following rules**: | ||
|
||
1. Each row must contain the digits `1-9` without repetition. | ||
2. Each column must contain the digits `1-9` without repetition. | ||
3. Each of the nine `3 x 3` sub-boxes of the grid must contain the digits `1-9` without repetition. | ||
|
||
**Note:** | ||
|
||
* A Sudoku board (partially filled) could be valid but is not necessarily solvable. | ||
* Only the filled cells need to be validated according to the mentioned rules. | ||
|
||
**Example 1:** | ||
|
||
 | ||
|
||
**Input:** | ||
|
||
board = | ||
[["5","3",".",".","7",".",".",".","."] | ||
,["6",".",".","1","9","5",".",".","."] | ||
,[".","9","8",".",".",".",".","6","."] | ||
,["8",".",".",".","6",".",".",".","3"] | ||
,["4",".",".","8",".","3",".",".","1"] | ||
,["7",".",".",".","2",".",".",".","6"] | ||
,[".","6",".",".",".",".","2","8","."] | ||
,[".",".",".","4","1","9",".",".","5"] | ||
,[".",".",".",".","8",".",".","7","9"]] | ||
|
||
**Output:** true | ||
|
||
**Example 2:** | ||
|
||
**Input:** | ||
|
||
board = | ||
[["8","3",".",".","7",".",".",".","."] | ||
,["6",".",".","1","9","5",".",".","."] | ||
,[".","9","8",".",".",".",".","6","."] | ||
,["8",".",".",".","6",".",".",".","3"] | ||
,["4",".",".","8",".","3",".",".","1"] | ||
,["7",".",".",".","2",".",".",".","6"] | ||
,[".","6",".",".",".",".","2","8","."] | ||
,[".",".",".","4","1","9",".",".","5"] | ||
,[".",".",".",".","8",".",".","7","9"]] | ||
|
||
**Output:** false | ||
|
||
**Explanation:** Same as Example 1, except with the **5** in the top left corner being modified to **8**. Since there are two 8's in the top left 3x3 sub-box, it is invalid. | ||
|
||
**Constraints:** | ||
|
||
* `board.length == 9` | ||
* `board[i].length == 9` | ||
* `board[i][j]` is a digit `1-9` or `'.'`. |
52 changes: 52 additions & 0 deletions
src/main/java/g0001_0100/s0037_sudoku_solver/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
37\. Sudoku Solver | ||
|
||
Hard | ||
|
||
Write a program to solve a Sudoku puzzle by filling the empty cells. | ||
|
||
A sudoku solution must satisfy **all of the following rules**: | ||
|
||
1. Each of the digits `1-9` must occur exactly once in each row. | ||
2. Each of the digits `1-9` must occur exactly once in each column. | ||
3. Each of the digits `1-9` must occur exactly once in each of the 9 `3x3` sub-boxes of the grid. | ||
|
||
The `'.'` character indicates empty cells. | ||
|
||
**Example 1:** | ||
|
||
 | ||
|
||
**Input:** | ||
|
||
board = [["5","3",".",".","7",".",".",".","."], | ||
["6",".",".","1","9","5",".",".","."], | ||
[".","9","8",".",".",".",".","6","."], | ||
["8",".",".",".","6",".",".",".","3"], | ||
["4",".",".","8",".","3",".",".","1"], | ||
["7",".",".",".","2",".",".",".","6"], | ||
[".","6",".",".",".",".","2","8","."], | ||
[".",".",".","4","1","9",".",".","5"], | ||
[".",".",".",".","8",".",".","7","9"]] | ||
|
||
**Output:** | ||
|
||
[["5","3","4","6","7","8","9","1","2"], | ||
["6","7","2","1","9","5","3","4","8"], | ||
["1","9","8","3","4","2","5","6","7"], | ||
["8","5","9","7","6","1","4","2","3"], | ||
["4","2","6","8","5","3","7","9","1"], | ||
["7","1","3","9","2","4","8","5","6"], | ||
["9","6","1","5","3","7","2","8","4"], | ||
["2","8","7","4","1","9","6","3","5"], | ||
["3","4","5","2","8","6","1","7","9"]] | ||
|
||
**Explanation:** The input board is shown above and the only valid solution is shown below: | ||
|
||
 | ||
|
||
**Constraints:** | ||
|
||
* `board.length == 9` | ||
* `board[i].length == 9` | ||
* `board[i][j]` is a digit or `'.'`. | ||
* It is **guaranteed** that the input board has only one solution. |
41 changes: 41 additions & 0 deletions
src/main/java/g0001_0100/s0038_count_and_say/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
38\. Count and Say | ||
|
||
Medium | ||
|
||
The **count-and-say** sequence is a sequence of digit strings defined by the recursive formula: | ||
|
||
* `countAndSay(1) = "1"` | ||
* `countAndSay(n)` is the way you would "say" the digit string from `countAndSay(n-1)`, which is then converted into a different digit string. | ||
|
||
To determine how you "say" a digit string, split it into the **minimal** number of groups so that each group is a contiguous section all of the **same character.** Then for each group, say the number of characters, then say the character. To convert the saying into a digit string, replace the counts with a number and concatenate every saying. | ||
|
||
For example, the saying and conversion for digit string `"3322251"`: | ||
|
||
 | ||
|
||
Given a positive integer `n`, return _the_ `nth` _term of the **count-and-say** sequence_. | ||
|
||
**Example 1:** | ||
|
||
**Input:** n = 1 | ||
|
||
**Output:** "1" | ||
|
||
**Explanation:** This is the base case. | ||
|
||
**Example 2:** | ||
|
||
**Input:** n = 4 | ||
|
||
**Output:** "1211" | ||
|
||
**Explanation:** | ||
|
||
countAndSay(1) = "1" | ||
countAndSay(2) = say "1" = one 1 = "11" | ||
countAndSay(3) = say "11" = two 1's = "21" | ||
countAndSay(4) = say "21" = one 2 + one 1 = "12" + "11" = "1211" | ||
|
||
**Constraints:** | ||
|
||
* `1 <= n <= 30` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.