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 1b43791

Browse files
add recent submissions and walk-throughs
1 parent 07d5a3e commit 1b43791

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

‎Kangli/README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
11
Keeping a record of thoughts behind solving certain problems
22

3+
1/4/18 Making some catch-up edits.
4+
5+
**387: First Unique Character in a String-**
6+
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
7+
Examples:
8+
s = "leetcode"
9+
return 0.
10+
s = "loveleetcode",
11+
return 2.
12+
Note: You may assume the string contain only lowercase letters.
13+
14+
Thoughts: Straightforward use of a hash to store the counts of each letter in the string. Then iterate the string again from the beginning and return the first letter with count of 1.
15+
[Submission](https://github.com/kanglicheng/python-leetcode/blob/mySolutions/Kangli/Strings/firstUniqueChar.py)
16+
17+
**443: String Compression-** Given an array of characters, compress it in-place. The length after compression must always be smaller than or equal to the original array. Every element of the array should be a character (not int) of length 1. After you are done modifying the input array in-place, return the new length of the array.
18+
19+
Example:
20+
Input:
21+
["a","a","b","b","c","c","c"]
22+
Output:
23+
Return 6, and the first 6 characters of the input array should be: ["a","2","b","2","c","3"]
24+
Explanation:
25+
"aa" is replaced by "a2". "bb" is replaced by "b2". "ccc" is replaced by "c3".
26+
27+
Thoughts: Easy if not doing it in place. I made an extra array, added the character and added its count if count > 1.
28+
[Submission](https://github.com/kanglicheng/python-leetcode/blob/mySolutions/Kangli/Strings/stringCompression.py)
29+
330
10/27/17
431
**219: Contains Duplicate II-** Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.
532
Thoughts:
633
Use a dictionary to store each integer and its index in nums as key, value pairs.
734
If a value is already in the dictionary, check whether index difference <= k.
835

936
Implementation: did not pass on first 2 tries, failed for [1, 0, 1, 1, ], 1 (true got false). Need to update
10-
index if value already in dictionary but i - d[n] > k.
37+
index if value already in dictionary but i - d[n] > k.
38+
[Submission](https://github.com/kanglicheng/python-leetcode/blob/mySolutions/Kangli/Hash%20Table/containsDuplicate_II.py)
1139

1240
**49: Group Anagrams-** Given an array of strings, group anagrams together.
1341
For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],
@@ -18,6 +46,7 @@ Return:
1846
["bat"]
1947
]
2048
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).
49+
[Submission](https://github.com/kanglicheng/python-leetcode/blob/mySolutions/Kangli/Hash%20Table/group_anagrams.py)
2150

2251
11/7/17
2352
**206: Reverse Linked List**

0 commit comments

Comments
(0)

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