Skip to content

Commit 3e2f69a

Browse files
[LEET-000] clean up comments
1 parent ec7b601 commit 3e2f69a

24 files changed

+306
-24
lines changed

leetcode-algorithms/src/main/java/com/stevesun/solutions/BSTIterator_using_q.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import java.util.LinkedList;
66
import java.util.Queue;
77

8-
/**173. Binary Search Tree Iterator QuestionEditorial Solution My Submissions
9-
Total Accepted: 56053
10-
Total Submissions: 154876
11-
Difficulty: Medium
8+
/**173. Binary Search Tree Iterator
129
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.
1310
1411
Calling next() will return the next smallest number in the BST.

leetcode-algorithms/src/main/java/com/stevesun/solutions/CombinationSumIII.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
import java.util.*;
44

5+
/**Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
6+
7+
8+
Example 1:
9+
10+
Input: k = 3, n = 7
11+
12+
Output:
13+
14+
[[1,2,4]]
15+
16+
Example 2:
17+
18+
Input: k = 3, n = 9
19+
20+
Output:
21+
22+
[[1,2,6], [1,3,5], [2,3,4]]*/
523
public class CombinationSumIII {
624
public List<List<Integer>> combinationSum3(int k, int n) {
725
List<List<Integer>> result = new ArrayList();

leetcode-algorithms/src/main/java/com/stevesun/solutions/Combinations.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package com.stevesun.solutions;
22
import java.util.*;
33

4-
public class Combinations {
5-
//I'm glad that I made this one AC'ed the first time I submitted it.
6-
//After finishing three similar problems! Cool!
4+
/**Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
5+
6+
For example,
7+
If n = 4 and k = 2, a solution is:
78
9+
[
10+
[2,4],
11+
[3,4],
12+
[2,3],
13+
[1,2],
14+
[1,3],
15+
[1,4],
16+
]*/
17+
public class Combinations {
818
public List<List<Integer>> combine(int n, int k) {
919
List<List<Integer>> result = new ArrayList();
1020
int[] nums = new int[n];

leetcode-algorithms/src/main/java/com/stevesun/solutions/DecodeWays.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
package com.stevesun.solutions;
22
import java.util.*;
33
/**
4-
* Created by fishercoder1534 on 10/3/16.
4+
* A message containing letters from A-Z is being encoded to numbers using the following mapping:
5+
6+
'A' -> 1
7+
'B' -> 2
8+
...
9+
'Z' -> 26
10+
Given an encoded message containing digits, determine the total number of ways to decode it.
11+
12+
For example,
13+
Given encoded message "12", it could be decoded as "AB" (1 2) or "L" (12).
14+
15+
The number of ways decoding "12" is 2.
516
*/
617
public class DecodeWays {
718
/**Then I found this post is very concise: https://discuss.leetcode.com/topic/35840/java-clean-dp-solution-with-explanation*/

leetcode-algorithms/src/main/java/com/stevesun/solutions/DesignPhoneDirectory.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,37 @@
55
import java.util.Queue;
66
import java.util.Set;
77

8+
/**Design a Phone Directory which supports the following operations:
9+
10+
get: Provide a number which is not assigned to anyone.
11+
check: Check if a number is available or not.
12+
release: Recycle or release a number.
13+
Example:
14+
15+
// Init a phone directory containing a total of 3 numbers: 0, 1, and 2.
16+
PhoneDirectory directory = new PhoneDirectory(3);
17+
18+
// It can return any available phone number. Here we assume it returns 0.
19+
directory.get();
20+
21+
// Assume it returns 1.
22+
directory.get();
23+
24+
// The number 2 is available, so return true.
25+
directory.check(2);
26+
27+
// It returns 2, the only number that is left.
28+
directory.get();
29+
30+
// The number 2 is no longer available, so return false.
31+
directory.check(2);
32+
33+
// Release number 2 back to the pool.
34+
directory.release(2);
35+
36+
// Number 2 is available again, return true.
37+
directory.check(2);
38+
*/
839
public class DesignPhoneDirectory {
940

1041
private class PhoneDirectory {

leetcode-algorithms/src/main/java/com/stevesun/solutions/RandomPickIndex.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
import java.util.List;
66
import java.util.Map;
77

8+
/**Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.
9+
10+
Note:
11+
The array size can be very large. Solution that uses too much extra space will not pass the judge.
12+
13+
Example:
14+
15+
int[] nums = new int[] {1,2,3,3,3};
16+
Solution solution = new Solution(nums);
17+
18+
// pick(3) should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.
19+
solution.pick(3);
20+
21+
// pick(1) should return 0. Since in the array only nums[0] is equal to 1.
22+
solution.pick(1);*/
823
public class RandomPickIndex {
924

1025
}

leetcode-algorithms/src/main/java/com/stevesun/solutions/RandomizedCollection.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import java.util.Map;
55
import java.util.Random;
66

7-
/**381. Insert Delete GetRandom O(1) - Duplicates allowed QuestionEditorial Solution My Submissions
8-
Total Accepted: 190
9-
Total Submissions: 613
10-
Difficulty: Medium
7+
/**381. Insert Delete GetRandom O(1) - Duplicates allowed
8+
*
119
Design a data structure that supports all following operations in average O(1) time.
1210
1311
Note: Duplicate elements are allowed.

leetcode-algorithms/src/main/java/com/stevesun/solutions/RandomizedSet.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import java.util.Random;
88
import java.util.Set;
99

10-
/**This solution got AC'ed. Although it's not really doing random 8/4/2016, it got rejected ever since because they added test case
10+
11+
public class RandomizedSet {
12+
/**This solution got AC'ed. Although it's not really doing random 8/4/2016, it got rejected ever since because they added test case
1113
* to see if it's really randomized.
1214
* Now, they've updated the test case and also the question description: Each element must have the same probability of being returned.*/
13-
public class RandomizedSet {
14-
15+
1516
Set<Integer> set;
1617

1718
/** Initialize your data structure here. */

leetcode-algorithms/src/main/java/com/stevesun/solutions/RangeAddition.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
package com.stevesun.solutions;
22

3+
/**Assume you have an array of length n initialized with all 0's and are given k update operations.
4+
5+
Each operation is represented as a triplet: [startIndex, endIndex, inc] which increments each element of subarray A[startIndex ... endIndex] (startIndex and endIndex inclusive) with inc.
6+
7+
Return the modified array after all k operations were executed.
8+
9+
Example:
10+
11+
Given:
12+
13+
length = 5,
14+
updates = [
15+
[1, 3, 2],
16+
[2, 4, 3],
17+
[0, 2, -2]
18+
]
19+
20+
Output:
21+
22+
[-2, 0, 3, 5, 3]
23+
Explanation:
24+
25+
Initial state:
26+
[ 0, 0, 0, 0, 0 ]
27+
28+
After applying operation [1, 3, 2]:
29+
[ 0, 2, 2, 2, 0 ]
30+
31+
After applying operation [2, 4, 3]:
32+
[ 0, 2, 5, 5, 3 ]
33+
34+
After applying operation [0, 2, -2]:
35+
[-2, 0, 3, 5, 3 ]
36+
Hint:
37+
38+
Thinking of using advanced data structures? You are thinking it too complicated.
39+
For each update operation, do you really need to update all elements between i and j?
40+
Update only the first and end element is sufficient.
41+
The optimal time complexity is O(k + n) and uses O(1) extra space.*/
342
public class RangeAddition {
443
/**Previously AC'ed brute force solution results in TLE now.*/
544
public static int[] getModifiedArray_TLE(int length, int[][] updates) {

leetcode-algorithms/src/main/java/com/stevesun/solutions/RectangleArea.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.stevesun.solutions;
22

3+
/**Find the total area covered by two rectilinear rectangles in a 2D plane.
4+
5+
Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.
6+
7+
Rectangle Area
8+
Assume that the total area is never beyond the maximum possible value of int.*/
39
public class RectangleArea {
410

511
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {

0 commit comments

Comments
 (0)