Skip to content

Commit 23f1e57

Browse files
committed
Modify Comments
1 parent ebe4fe8 commit 23f1e57

38 files changed

+229
-361
lines changed

src/chapter01ArraysAndStrings/CheckPermutation.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
/**
44
*
5-
* @author chengfeili
6-
* Jun 15, 2017 11:48:50 AM
7-
*
8-
* Problem: Given two strings, write a method to decide if one is a
9-
* permutation of other.
5+
* Problem: Given two strings, write a method to decide if one is a permutation
6+
* of other.
107
*
11-
* Solution: clarify case sensitive and whitespace
8+
* Solution: clarify case sensitive and whitespace
129
*
1310
*/
1411
public class CheckPermutation {
15-
// method1: sort then compare.
12+
/**
13+
* method1: sort then compare.
14+
*/
1615

17-
// method2: Check if two strings have identical character counts
16+
/**
17+
* method2: Check if two strings have identical character counts
18+
*/
1819
public boolean perm(String s1, String s2) {
1920
if (s1 == null || s2 == null || s1.length() != s2.length()) {
2021
return false;

src/chapter01ArraysAndStrings/IsUnique.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22

33
/**
44
*
5-
* @author chengfeili
6-
* Jun 15, 2017 11:29:15 AM
7-
*
8-
* Problem: Implement an algorithm to determine if a string has all
9-
* unique characters. No extra data structure.
10-
*
11-
* Solution:
5+
* Problem: Implement an algorithm to determine if a string has all unique
6+
* characters. No extra data structure.
127
*
138
*/
149

1510
public class IsUnique {
1611
/**
17-
*
1812
* O(N) O(1)
1913
*/
2014
public boolean isUnique1(String s) {
@@ -33,8 +27,8 @@ public boolean isUnique1(String s) {
3327
}
3428

3529
/**
36-
* Assume the string only uses lowercase letters. Use just a single int(32bits)
37-
* to save more space complexity
30+
* Assume the string only uses lowercase letters. Use just a single
31+
* int(32bits) to save more space complexity
3832
*/
3933
public boolean isUnique2(String s) {
4034
if (s == null || s.length() > 26) {

src/chapter01ArraysAndStrings/OneAway.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22

33
/**
44
*
5-
* @author chengfeili
6-
* Jun 15, 2017 4:11:42 PM
5+
* Problem: One Away: There are three types of edits that can be performed on
6+
* strings: insert a character, remove a character, or replace a character.
7+
* Given two strings, write a function to check if they are one edit (or zero
8+
* edits) away.
79
*
8-
* Problem: One Away: There are three types of edits that can be
9-
* performed on strings: insert a character, remove a character, or
10-
* replace a character. Given two strings, write a function to check if
11-
* they are one edit (or zero edits) away.
12-
*
13-
* Solution:
10+
* Solution:
1411
*
1512
*/
1613
public class OneAway {
17-
// method1: replace, insert, delete.
18-
// It is clearer and easier to follow but has some duplicate code.
14+
/**
15+
* method1: replace, insert, delete.It is clearer and easier to follow but
16+
* has some duplicate code.
17+
*/
1918
public boolean oneEditAway(String s1, String s2) {
2019
if (s1 == null || s2 == null) {
2120
return false;
@@ -64,7 +63,9 @@ private boolean insert(String s1, String s2) {
6463
return true;
6564
}
6665

67-
// method2: Handle replace and insert in the same method;
66+
/**
67+
* method2: Handle replace and insert in the same method;
68+
*/
6869
public boolean method2(String s1, String s2) {
6970
if (s1 == null || s2 == null || s1.length() - s2.length() == 0) {
7071
return false;

src/chapter01ArraysAndStrings/PalindromePermutation.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22

33
/**
44
*
5-
* @author chengfeili
6-
* Jun 15, 2017 3:46:14 PM
5+
* Problem: Palindrome Permutation: Given a string, write a function to check if
6+
* it is a permutation of a palindrome. A palindrome is a word or phrase that is
7+
* the same forwards and backwards. A permutation is a rearrangement of letters.
8+
* The palindrome does not need to be limited to just dictionary words.
79
*
8-
* Problem: Palindrome Permutation: Given a string, write a function to
9-
* check if it is a permutation of a palindrome. A palindrome is a word
10-
* or phrase that is the same forwards and backwards. A permutation is a
11-
* rearrangement of letters. The palindrome does not need to be limited
12-
* to just dictionary words.
13-
*
14-
* EXAMPLE Input: tact coa
15-
* Output: True (permutations: "taco cat'; "atco eta·; etc.)
16-
*
17-
* Solution:
10+
* EXAMPLE Input: tact coa Output: True (permutations: "taco cat'; "atco eta·;
11+
* etc.)
1812
*
1913
*/
2014
public class PalindromePermutation {

src/chapter01ArraysAndStrings/RotateMatrix.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
package chapter01ArraysAndStrings;
22

33
/**
4-
*
5-
* @author chengfeili
6-
* Jun 15, 2017 6:23:31 PM
7-
*
8-
* Problem: Rotate Matrix: Given an image represented by an NxN matrix,
9-
* where each pixel in the image is 4 bytes, write a method to rotate
10-
* the image by 90 degrees. Can you do this in place?
11-
*
12-
* Solution:
4+
* Problem: Rotate Matrix: Given an image represented by an NxN matrix, where
5+
* each pixel in the image is 4 bytes, write a method to rotate the image by 90
6+
* degrees. Can you do this in place?
137
*
148
*/
159
public class RotateMatrix {

src/chapter01ArraysAndStrings/StringCompression.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22

33
/**
44
*
5-
* @author chengfeili
6-
* Jun 15, 2017 4:56:35 PM
5+
* Problem: Implement a method to perform basic string compression using the
6+
* counts of repeated characters.
77
*
8-
* Problem: Implement a method to perform basic string compression using
9-
* the counts of repeated characters.
10-
*
11-
* For example, the string aabcccccaaa would become a2blc5a3. If the
12-
* "compressed" string would not become smaller than the original
13-
* string, your method should return the original string. You can assume
14-
* the string has only uppercase and lowercase letters (a - z)
15-
*
16-
* Solution:
8+
* For example, the string aabcccccaaa would become a2blc5a3. If the
9+
* "compressed" string would not become smaller than the original string, your
10+
* method should return the original string. You can assume the string has only
11+
* uppercase and lowercase letters (a - z)
1712
*
1813
*/
1914
public class StringCompression {
@@ -22,7 +17,7 @@ public String compressBad(String str) {
2217
int countConsecutive = 0;
2318
for (int i = 0; i < str.length(); i++) {
2419
countConsecutive++;
25-
/*
20+
/**
2621
* If next character is different than current, append this char to
2722
* result.
2823
*/

src/chapter01ArraysAndStrings/StringRotation.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
/**
44
*
5-
* @author chengfeili
6-
* Jun 15, 2017 6:58:12 PM
7-
*
8-
* Problem: Assume you have a method isSubstring which checks if one
9-
* word is a substring of another. Given two Strings, check if s2 is a
10-
* rotation of s1 using only one call to isSubstring
11-
*
12-
* Solution:
5+
* Problem: Assume you have a method isSubstring which checks if one word is a
6+
* substring of another. Given two Strings, check if s2 is a rotation of s1
7+
* using only one call to isSubstring
138
*
149
*/
1510
public class StringRotation {

src/chapter01ArraysAndStrings/Urlify.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
/**
44
*
5-
* @author chengfeili
6-
* Jun 15, 2017 12:00:35 PM
5+
* Problem: Write a method to replace all spaces in a string with '%20 You may
6+
* assume that the string has sufficient space at the end to hold the additional
7+
* characters, and that you are given the "true" length of the string. (Note: if
8+
* implementing in Java, please use a character array so that you can perform
9+
* this operation in place.) EXAMPLE Input: "Mr John Smith ", 13 Output:
10+
* "Mr%20John%20Smith"
711
*
8-
* Problem: Write a method to replace all spaces in a string
9-
* with '%20 You may assume that the string has sufficient space at the
10-
* end to hold the additional characters, and that you are given the
11-
* "true" length of the string. (Note: if implementing in Java, please
12-
* use a character array so that you can perform this operation in
13-
* place.)
14-
* EXAMPLE Input: "Mr John Smith ", 13
15-
* Output: "Mr%20John%20Smith"
16-
*
17-
* Solution: Start from the end and work backwards
12+
* Solution: Start from the end and work backwards
1813
*
1914
*/
2015
public class Urlify {

src/chapter01ArraysAndStrings/ZeroMatrix.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@
22

33
/**
44
*
5-
* @author chengfeili
6-
* Jun 15, 2017 6:35:39 PM
7-
*
8-
* Problem: Write an algorithm such that if an element in an MxN matrix
9-
* is 0, its entire row and column are set to 0.
5+
* Problem: Write an algorithm such that if an element in an MxN matrix is 0,
6+
* its entire row and column are set to 0.
107
*
11-
* Solution: We can reduce the space to O(1) by using the first row as a
12-
* replacement for the row array and the first column as a replacement
13-
* for the column array. This works as follows:
14-
* 1. Check if the first row and first column have any zeros, and set
15-
* variables rowHasZero and columnHasZero. (We'll nullify the first row and
16-
* first column later, if necessary.)
17-
* 2. Iterate through the rest of the matrix, seeing matrix[i][0) and
18-
* matrix[0) [j] to zero whenever there's a zero in
19-
* matrix[i][j].
20-
* 3. Iterate through rest of matrix, nullifying row i if
21-
* there's a zero in matrix[i][0].
22-
* 4. Iterate through rest of matrix,
23-
* nullifying column j if there's a zero in matrix[ 0][ j].
24-
* 5. Nullify the first row and first column, if necessary (based on values from Step 1).
8+
* Solution: We can reduce the space to O(1) by using the first row as a
9+
* replacement for the row array and the first column as a replacement for the
10+
* column array. This works as follows: 1. Check if the first row and first
11+
* column have any zeros, and set variables rowHasZero and columnHasZero. (We'll
12+
* nullify the first row and first column later, if necessary.) 2. Iterate
13+
* through the rest of the matrix, seeing matrix[i][0) and matrix[0) [j] to zero
14+
* whenever there's a zero in matrix[i][j]. 3. Iterate through rest of matrix,
15+
* nullifying row i if there's a zero in matrix[i][0]. 4. Iterate through rest
16+
* of matrix, nullifying column j if there's a zero in matrix[ 0][ j]. 5.
17+
* Nullify the first row and first column, if necessary (based on values from
18+
* Step 1).
2519
*
2620
*/
2721
public class ZeroMatrix {

src/chapter02LinkedList/DeleteMiddleNode.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22

33
/**
44
*
5-
* @author chengfeili
6-
* Jun 19, 2017 9:33:21 PM
5+
* Problem: Implement an algorithm to delete a node in the middle (i.e., any
6+
* node but the first and last node, not necessarily the exact middle) of a
7+
* singly linked list, given only access to that node.
78
*
8-
* Problem: Implement an algorithm to delete a node in the middle (i.e.,
9-
* any node but the first and last node, not necessarily the exact
10-
* middle) of a singly linked list, given only access to that node.
11-
*
12-
* EXAMPLE lnput:the node c from the linked list a->b->c->d->e->f
13-
* Result: nothing is returned, but the new linked list looks like
14-
* a->b->d->e->f
15-
*
16-
* Solution:
9+
* EXAMPLE lnput:the node c from the linked list a->b->c->d->e->f Result:
10+
* nothing is returned, but the new linked list looks like a->b->d->e->f
1711
*
1812
*/
1913
public class DeleteMiddleNode {

0 commit comments

Comments
 (0)