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 172882f

Browse files
Update README.md
1 parent d02b92e commit 172882f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎Kangli/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Hint: Related problem: Reverse Words in a String II. An "easy" problem but with
1414
*Thoughts: Really struggled with the constraint of doing it in place. So tried solving it with extra space first.
1515
Just append the elements in the correct positions in the new results array. But coming up with the correct positions requires thinking about two conditions. As we iterate through the input nums, we simply put put nums[i] at res[i+k] if i+k is a valid index (i + k < len(nums) ). But if i + k exceeds len(nums), what to do? Also k can be any positive number, meaning it could be several times len(nums). I worked out a few examples arr = [1, 2, 3], k=1, k= 2, k = 5 etc. Then I found the pattern that the correct position corresponds to (i + k) % len(nums), for any i and k. This is also correct mathematically because we are really looking for the number (i + k) that "wraps around" len(nums), which is exactly what modulo arithmetic can be used for.*
1616

17-
*I later looked up an in-place solution that pops the last item of the array and inserts it to the beginning, repeating for k % len(nums) times.*
17+
*I later looked up an in-place solution that pops the last item of the array and inserts it to the beginning, repeating for k % len(nums) times.*
1818
[Submission](https://github.com/kanglicheng/python-leetcode/blob/mySolutions/Kangli/Arrays/rotateArray.py)
1919

2020

@@ -41,7 +41,7 @@ Explanation:
4141
"aa" is replaced by "a2". "bb" is replaced by "b2". "ccc" is replaced by "c3".
4242

4343
*Thoughts: Easy if not doing it in place. I made an extra array, added the character and added its count
44-
if count > 1. Return the length of new array at the end.*
44+
if count > 1. Return the length of new array at the end.*
4545
[Submission](https://github.com/kanglicheng/python-leetcode/blob/mySolutions/Kangli/Strings/stringCompression.py)
4646

4747
10/27/17
@@ -63,7 +63,7 @@ Return:
6363
["nat","tan"],
6464
["bat"]
6565
]
66-
*Thoughts: Using a dictionary (hash), insert each sorted string into the dictionary as keys, using the original string as the value. Need the values to be an array, so initialize the value of each key as [] and add the original string directly to [] each time. Could also use defaultdict (python specific).*
66+
*Thoughts: Using a dictionary (hash), insert each sorted string into the dictionary as keys, using the original string as the value. Need the values to be an array, so initialize the value of each key as [] and add the original string directly to [] each time. Could also use defaultdict (python specific).*
6767
[Submission](https://github.com/kanglicheng/python-leetcode/blob/mySolutions/Kangli/Hash%20Table/group_anagrams.py)
6868

6969
11/7/17

0 commit comments

Comments
(0)

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