From a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Fri, 27 Jun 2025 12:23:02 -0600 Subject: chore: remove old cpp and rust solutions --- other/lexicographically_small_string.cpp | 42 -------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 other/lexicographically_small_string.cpp (limited to 'other/lexicographically_small_string.cpp') diff --git a/other/lexicographically_small_string.cpp b/other/lexicographically_small_string.cpp deleted file mode 100644 index 3a58189..0000000 --- a/other/lexicographically_small_string.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "leetcode.h" - -/* - * given: 2 strings of same length ('s1', 's2'), & a string 'baseStr' - * s1[i] and s2[i] are equivalent characters - * eg. s1 = "abc", s2 = "cde", 'a' == 'c', 'b' == 'd', etc. - * return lexicographically smallest equivalent string of 'baseStr' by using - * equivalency information from 's1' & 's2' - */ - -class Solution { -public: - // union find - string smallestEquivalentString(string s1, string s2, string baseStr) { - vector ds(26, -1); - for (auto i = 0; i < s1.size(); ++i) - dsMerge(ds, s1[i] - 'a', s2[i] - 'a'); - for (auto i = 0; i < baseStr.size(); ++i) - baseStr[i] = dsFind(ds, baseStr[i] - 'a') + 'a'; - return baseStr; - } - -private: - int dsFind(vector &ds, int p) { - return ds[p] == -1 ? p : ds[p] = dsFind(ds, ds[p]); - } - void dsMerge(vector &ds, int p1, int p2) { - p1 = dsFind(ds, p1), p2 = dsFind(ds, p2); - if (p1 != p2) - ds[max(p1, p2)] = min(p1, p2); - } -}; - -int main() { - Solution obj; - cout << obj.smallestEquivalentString("parker", "morris", - "parser"); // expect: makkek - cout << obj.smallestEquivalentString("hello", "world", "hold"); // expect: - // hdld - cout << obj.smallestEquivalentString("leetcode", "programs", - "sourcecode"); // expect: aauaaaaada -} -- cgit v1.2.3