Daily Problem
Diffstat:
2 files changed, 23 insertions(+), 0 deletions(-)
@@ -0,0 +1,22 @@
class Solution {
public:
bool buddyStrings(const string &s, const string &goal) {
int a = -1, b = -1, dup = 0, count[26] = {0};
if (s.size() != goal.size()) return false;
for (int i = 0; i < s.size(); i++) {
if (count[s[i] & 0xF]) dup = 1;
count[s[i] & 0xF] = 1;
if (s[i] != goal[i]) {
if (a == -1)
a = i;
else if (b == -1)
b = i;
else
return false;
}
}
if (a == -1) return dup;
if (b == -1) return false;
return s[a] == goal[b] && s[b] == goal[a];
}
};
@@ -360,6 +360,7 @@
for solving problems.
| 0844 | Easy | [Backspace String Compare](Problems/0844.cpp) |
| 0851 | Medium | [Loud and Rich](Problems/0851.cpp) |
| 0853 | Medium | [Car Fleet](Problems/0853.cpp) |
| 0859 | Easy | [Buddy Strings](Problems/0859.cpp) |
| 0864 | Hard | [Shortest Path to Get All Keys](Problems/0864.cpp) |
| 0872 | Easy | [Leaf-Similar Trees](Problems/0872.cpp) |
| 0875 | Medium | [Koko Eating Bananas](Problems/0875.cpp) |