about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-12-25T03·52+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-12-25T03·52+0000
commit93d7b5d8eaea4125c3ddd774bb2b8949b1ccce68 (patch)
tree439e3f33ac84ccc5bfc39c4f7e113c25b99534d5
parentc34a3e2e97ce640a5ab7042d1ec977be71088ddd (diff)
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)
```
-rw-r--r--scratch/facebook/leetcode.org6
1 files changed, 3 insertions, 3 deletions
diff --git a/scratch/facebook/leetcode.org b/scratch/facebook/leetcode.org
index 346a570427a7..fad137f27083 100644
--- a/scratch/facebook/leetcode.org
+++ b/scratch/facebook/leetcode.org
@@ -111,9 +111,9 @@
    https://leetcode.com/problems/longest-repeating-character-replacement/
 ** TODO Minimum Window Substring
    https://leetcode.com/problems/minimum-window-substring/
-** TODO Valid Anagram
+** DONE Valid Anagram
    https://leetcode.com/problems/valid-anagram/
-** TODO Group Anagrams
+** DONE Group Anagrams
    https://leetcode.com/problems/group-anagrams/
 ** DONE Valid Parentheses
    https://leetcode.com/problems/valid-parentheses/
@@ -123,7 +123,7 @@
    https://leetcode.com/problems/longest-palindromic-substring/
 ** TODO 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/
 * Tree
 ** DONE Maximum Depth of Binary Tree