commit a527ca5155d1ae689854af214e3a623580c9a05c
parent beabc2772b11bea2204a9d1006e8d437a2ad9220
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sun, 22 Jan 2023 12:58:57 +0100
LeetCode 75 I: Day 2
Diffstat:
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/Problems/0205.cpp b/Problems/0205.cpp
@@ -0,0 +1,18 @@
+class Solution {
+public:
+ bool isIsomorphic(string s, string t) {
+ unordered_map<char, char> um;
+ unordered_set<char> us;
+
+ for (int i = 0; i < s.size(); i++) {
+ if (!um.count(s[i])) {
+ if (us.count(t[i])) return false;
+ um[s[i]] = t[i];
+ us.insert(t[i]);
+ } else if (um[s[i]] != t[i])
+ return false;
+ }
+
+ return true;
+ }
+};
diff --git a/Problems/0392.cpp b/Problems/0392.cpp
@@ -1,9 +1,9 @@
class Solution {
public:
bool isSubsequence(string s, string t) {
- int j = 0;
- for (int i = 0; i < t.size() && j < s.size(); i++)
- if (t[i] == s[j]) j++;
- return j == s.size();
+ int i = 0;
+ for (int j = 0; j < t.size() && i < s.size(); j++)
+ if (s[i] == t[j]) i++;
+ return i == s.size();
}
};
diff --git a/README.md b/README.md
@@ -104,6 +104,7 @@ for solving problems.
| 0199 | Medium | [Binary Tree Right Side View](Problems/0199.cpp) |
| 0200 | Medium | [Number of Islands](Problems/0200.cpp) |
| 0203 | Easy | [Remove Linked List Elements](Problems/0203.cpp) |
+| 0205 | Easy | [Isomorphic Strings](Problems/0205.cpp) |
| 0206 | Easy | [Reverse Linked List](Problems/0206.cpp) |
| 0207 | Medium | [Course Schedule](Problems/0207.cpp) |
| 0209 | Medium | [Minimum Size Subarray Sum](Problems/0209.cpp) |