Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f09ac6e

Browse files
author
Shuo
authored
Merge pull request #317 from openset/develop
Update: Hints
2 parents affd056 + e640b1f commit f09ac6e

File tree

10 files changed

+84
-21
lines changed

10 files changed

+84
-21
lines changed

‎problems/employee-free-time/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
1. [Merge Intervals](https://github.com/openset/leetcode/tree/master/problems/merge-intervals) (Medium)
1818

1919
### Hints
20-
1. Take all the intervals and do an "events" (or "line sweep") approach - an event of (x, OPEN) increases the number of active intervals, while (x, CLOSE) decreases it.
20+
<details>
21+
<summary>Hint 1</summary>
22+
Take all the intervals and do an "events" (or "line sweep") approach - an event of (x, OPEN) increases the number of active intervals, while (x, CLOSE) decreases it.
2123

2224
Processing in sorted order from left to right, if the number of active intervals is zero, then you crossed a region of common free time.
25+
</details>

‎problems/find-minimum-in-rotated-sorted-array/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,19 @@
3838
1. [Find Minimum in Rotated Sorted Array II](https://github.com/openset/leetcode/tree/master/problems/find-minimum-in-rotated-sorted-array-ii) (Hard)
3939

4040
### Hints
41-
1. Array was originally in ascending order. Now that the array is rotated, there would be a point in the array where there is a small deflection from the increasing sequence. eg. The array would be something like [4, 5, 6, 7, 0, 1, 2].
42-
1. You can divide the search space into two and see which direction to go.
41+
<details>
42+
<summary>Hint 1</summary>
43+
Array was originally in ascending order. Now that the array is rotated, there would be a point in the array where there is a small deflection from the increasing sequence. eg. The array would be something like [4, 5, 6, 7, 0, 1, 2].
44+
</details>
45+
<details>
46+
<summary>Hint 2</summary>
47+
You can divide the search space into two and see which direction to go.
4348
Can you think of an algorithm which has O(logN) search complexity?
44-
1. <ol>
49+
</details>
50+
<details>
51+
<summary>Hint 3</summary>
52+
<ol>
4553
<li>All the elements to the left of inflection point > first element of the array.</li>
4654
<li>All the elements to the right of inflection point < first element of the array.</li>
4755
<ol>
56+
</details>

‎problems/largest-number-at-least-twice-of-others/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@
4747
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
4848

4949
### Hints
50-
1. Scan through the array to find the unique largest element `m`, keeping track of it's index `maxIndex`.
50+
<details>
51+
<summary>Hint 1</summary>
52+
Scan through the array to find the unique largest element `m`, keeping track of it's index `maxIndex`.
5153

5254
Scan through the array again. If we find some `x != m` with `m < 2*x`, we should return `-1`.
5355

5456
Otherwise, we should return `maxIndex`.
57+
</details>

‎problems/majority-element-ii/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
1. [Majority Element](https://github.com/openset/leetcode/tree/master/problems/majority-element) (Easy)
3131

3232
### Hints
33-
1. How many majority elements could it possibly have?
33+
<details>
34+
<summary>Hint 1</summary>
35+
How many majority elements could it possibly have?
3436
<br/>
3537
Do you have a better hint? <a href="mailto:admin@leetcode.com?subject=Hints for Majority Element II" target="_blank">Suggest it</a>!
38+
</details>

‎problems/minimum-window-substring/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@
3737
1. [Minimum Window Subsequence](https://github.com/openset/leetcode/tree/master/problems/minimum-window-subsequence) (Hard)
3838

3939
### Hints
40-
1. Use two pointers to create a window of letters in <b>S</b>, which would have all the characters from <b>T</b>.
41-
1. Since you have to find the minimum window in <b>S</b> which has all the characters from <b>T</b>, you need to expand and contract the window using the two pointers and keep checking the window for all the characters. This approach is also called Sliding Window Approach.
40+
<details>
41+
<summary>Hint 1</summary>
42+
Use two pointers to create a window of letters in <b>S</b>, which would have all the characters from <b>T</b>.
43+
</details>
44+
<details>
45+
<summary>Hint 2</summary>
46+
Since you have to find the minimum window in <b>S</b> which has all the characters from <b>T</b>, you need to expand and contract the window using the two pointers and keep checking the window for all the characters. This approach is also called Sliding Window Approach.
4247

4348
<br><br>
4449
<pre>
@@ -47,3 +52,4 @@ L ------------------------ R , Suppose this is the window that contains all char
4752
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp L----------------- R , this is the contracted window. We found a smaller window that still contains all the characters in <b>T</b>
4853

4954
When the window is no longer valid, start expanding again using the right pointer. </pre>
55+
</details>

‎problems/palindromic-substrings/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ The substrings with different start indexes or end indexes are counted as differ
4747
1. [Palindromic Substrings](https://github.com/openset/leetcode/tree/master/problems/palindromic-substrings) (Medium)
4848

4949
### Hints
50-
1. How can we reuse a previously computed palindrome to compute a larger palindrome?
51-
1. If "aba" is a palindrome, is "xabax" and palindrome? Similarly is "xabay" a palindrome?
52-
1. Complexity based hint:</br>
50+
<details>
51+
<summary>Hint 1</summary>
52+
How can we reuse a previously computed palindrome to compute a larger palindrome?
53+
</details>
54+
<details>
55+
<summary>Hint 2</summary>
56+
If "aba" is a palindrome, is "xabax" and palindrome? Similarly is "xabay" a palindrome?
57+
</details>
58+
<details>
59+
<summary>Hint 3</summary>
60+
Complexity based hint:</br>
5361
If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end pairs and O(n) palindromic checks. Can we reduce the time for palindromic checks to O(1) by reusing some previous computation?
62+
</details>

‎problems/parse-lisp-expression/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ of the final x in the add-expression. That final x will equal 2.
7979
1. [Basic Calculator IV](https://github.com/openset/leetcode/tree/master/problems/basic-calculator-iv) (Hard)
8080

8181
### Hints
82-
1. * If the expression starts with a digit or '-', it's an integer: return it.
82+
<details>
83+
<summary>Hint 1</summary>
84+
* If the expression starts with a digit or '-', it's an integer: return it.
8385

8486
* If the expression starts with a letter, it's a variable. Recall it by checking the current scope in reverse order.
8587

@@ -88,3 +90,4 @@ of the final x in the add-expression. That final x will equal 2.
8890
* For add and mult expressions, evaluate each token and return the addition or multiplication of them.
8991

9092
* For let expressions, evaluate each expression sequentially and assign it to the variable in the current scope, then return the evaluation of the final expression.
93+
</details>

‎problems/remove-comments/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ source = ["a/*comment", "line", "more_comment*/b"]
8585
1. [Ternary Expression Parser](https://github.com/openset/leetcode/tree/master/problems/ternary-expression-parser) (Medium)
8686

8787
### Hints
88-
1. Carefully parse each line according to the following rules:
88+
<details>
89+
<summary>Hint 1</summary>
90+
Carefully parse each line according to the following rules:
8991

9092
* If we start a block comment and we aren't in a block, then we will skip over the next two characters and change our state to be in a block.
9193

@@ -96,3 +98,4 @@ source = ["a/*comment", "line", "more_comment*/b"]
9698
* If we aren't in a block comment (and it wasn't the start of a comment), we will record the character we are at.
9799

98100
* At the end of each line, if we aren't in a block, we will record the line.
101+
</details>

‎problems/remove-invalid-parentheses/README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,34 @@
4040
1. [Valid Parentheses](https://github.com/openset/leetcode/tree/master/problems/valid-parentheses) (Easy)
4141

4242
### Hints
43-
1. Since we don't know which of the brackets can possibly be removed, we try out all the options!
44-
1. We can use recursion to try out all possibilities for the given expression. For each of the brackets, we have 2 options:
43+
<details>
44+
<summary>Hint 1</summary>
45+
Since we don't know which of the brackets can possibly be removed, we try out all the options!
46+
</details>
47+
<details>
48+
<summary>Hint 2</summary>
49+
We can use recursion to try out all possibilities for the given expression. For each of the brackets, we have 2 options:
4550

4651
<ol>
4752
<li> We keep the bracket and add it to the expression that we are building on the fly during recursion.</li>
4853
<li> OR, we can discard the bracket and move on.
4954
</ol>
50-
1. The one thing all these valid expressions have in common is that they will all be of the same length i.e. as compared to the original expression, all of these expressions will have the same number of characters removed.
55+
</details>
56+
<details>
57+
<summary>Hint 3</summary>
58+
The one thing all these valid expressions have in common is that they will all be of the same length i.e. as compared to the original expression, all of these expressions will have the same number of characters removed.
5159

5260
Can we somehow find the number of misplaced parentheses and use it in our solution?
53-
1. The one thing all these valid expressions have in common is that they will all be of the same length i.e. as compared to the original expression, all of these expressions will have the same number of characters removed.
61+
</details>
62+
<details>
63+
<summary>Hint 4</summary>
64+
The one thing all these valid expressions have in common is that they will all be of the same length i.e. as compared to the original expression, all of these expressions will have the same number of characters removed.
5465

5566
Can we somehow find the number of misplaced parentheses and use it in our solution?
56-
1. For every left parenthesis, we should have a corresponding right parenthesis. We can make use of two counters which keep track of misplaced left and right parenthesis and in one iteration we can find out these two values.
67+
</details>
68+
<details>
69+
<summary>Hint 5</summary>
70+
For every left parenthesis, we should have a corresponding right parenthesis. We can make use of two counters which keep track of misplaced left and right parenthesis and in one iteration we can find out these two values.
5771

5872
<pre>
5973
0 1 2 3 4 5 6 7
@@ -69,4 +83,8 @@ i = 7, left = 2, right = 2
6983
</pre>
7084

7185
We have 2 misplaced left and 2 misplaced right parentheses.
72-
1. We found out that the exact number of left and right parenthesis that has to be removed to get a valid expression. So, e.g. in a 1000 parentheses string, if there are 2 misplaced left and 2 misplaced right parentheses, after we are done discarding 2 left and 2 right parentheses, we will have only one option per remaining character in the expression i.e. to consider them. We can't discard them.
86+
</details>
87+
<details>
88+
<summary>Hint 6</summary>
89+
We found out that the exact number of left and right parenthesis that has to be removed to get a valid expression. So, e.g. in a 1000 parentheses string, if there are 2 misplaced left and 2 misplaced right parentheses, after we are done discarding 2 left and 2 right parentheses, we will have only one option per remaining character in the expression i.e. to consider them. We can't discard them.
90+
</details>

‎problems/roman-to-integer/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,20 @@ M 1000</pre>
7272
1. [Integer to Roman](https://github.com/openset/leetcode/tree/master/problems/integer-to-roman) (Medium)
7373

7474
### Hints
75-
1. I - 1</br>
75+
<details>
76+
<summary>Hint 1</summary>
77+
I - 1</br>
7678
V - 5</br>
7779
X - 10</br>
7880
L - 50</br>
7981
C - 100</br>
8082
D - 500</br>
8183
M - 1000</br>
82-
1. <b>Rules:</b></br>
84+
</details>
85+
<details>
86+
<summary>Hint 2</summary>
87+
<b>Rules:</b></br>
8388
* If I comes before V or X, subtract 1 eg: IV = 4 and IX = 9</br>
8489
* If X comes before L or C, subtract 10 eg: XL = 40 and XC = 90</br>
8590
* If C comes before D or M, subtract 100 eg: CD = 400 and CM = 900</br>
91+
</details>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /