Solve a few String questions
Valid Anagram
This one is a classic: `sorted(a) == sorted(b)`
Group Anagrams
Using product of prime numbers to create a key for anagrams is much faster than
sorting the characters in each word. It is also satisfyingly simple.
Encode and Decode Strings
My initial implementation was clumsy and prone to fail for edge-cases. A more
elegant solution is using something like:
```python
def encode(words):
  return "".join("{}:{}".format(len(x), x) for x in words)
```
			
			
This commit is contained in:
		
							parent
							
								
									c34a3e2e97
								
							
						
					
					
						commit
						93d7b5d8ea
					
				
					 1 changed files with 3 additions and 3 deletions
				
			
		|  | @ -111,9 +111,9 @@ | ||||||
|    https://leetcode.com/problems/longest-repeating-character-replacement/ |    https://leetcode.com/problems/longest-repeating-character-replacement/ | ||||||
| ** TODO Minimum Window Substring | ** TODO Minimum Window Substring | ||||||
|    https://leetcode.com/problems/minimum-window-substring/ |    https://leetcode.com/problems/minimum-window-substring/ | ||||||
| ** TODO Valid Anagram | ** DONE Valid Anagram | ||||||
|    https://leetcode.com/problems/valid-anagram/ |    https://leetcode.com/problems/valid-anagram/ | ||||||
| ** TODO Group Anagrams | ** DONE Group Anagrams | ||||||
|    https://leetcode.com/problems/group-anagrams/ |    https://leetcode.com/problems/group-anagrams/ | ||||||
| ** DONE Valid Parentheses | ** DONE Valid Parentheses | ||||||
|    https://leetcode.com/problems/valid-parentheses/ |    https://leetcode.com/problems/valid-parentheses/ | ||||||
|  | @ -123,7 +123,7 @@ | ||||||
|    https://leetcode.com/problems/longest-palindromic-substring/ |    https://leetcode.com/problems/longest-palindromic-substring/ | ||||||
| ** TODO Palindromic Substrings | ** TODO Palindromic Substrings | ||||||
|    https://leetcode.com/problems/palindromic-substrings/ |    https://leetcode.com/problems/palindromic-substrings/ | ||||||
| ** TODO Encode and Decode Strings (Leetcode Premium) | ** DONE Encode and Decode Strings (Leetcode Premium) | ||||||
|    https://leetcode.com/problems/encode-and-decode-strings/ |    https://leetcode.com/problems/encode-and-decode-strings/ | ||||||
| * Tree | * Tree | ||||||
| ** DONE Maximum Depth of Binary Tree | ** DONE Maximum Depth of Binary Tree | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue