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/num_nodes_sub_tree.cpp | 47 -------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 other/num_nodes_sub_tree.cpp (limited to 'other/num_nodes_sub_tree.cpp') diff --git a/other/num_nodes_sub_tree.cpp b/other/num_nodes_sub_tree.cpp deleted file mode 100644 index 4edb9ad..0000000 --- a/other/num_nodes_sub_tree.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "leetcode.h" - -class Solution { -public: - vector countSubTrees(int n, vvd & edges, string labels) { - vector ans(n); - int cnt[26] = {}; - vvd i(n); - for (auto e : edges) { - i[e[0]].push_back(e[1]); - i[e[1]].push_back(e[0]); - } - dfs(0, labels, i, cnt, ans); - return ans; - } - -private: - void dfs(int i, string labels, vvd & edges, int cnt[], - vector &ans) { - if (ans[i] == 0) { - ans[i] = 1; - for (auto j : edges[i]) { - int cnt1[26] = {}; - dfs(j, labels, edges, cnt1, ans); - for (auto k = 0; k < 26; ++k) - cnt[k] += cnt1[k]; - } - ans[i] = ++cnt[labels[i] - 'a']; - } - } -}; - -int main() { - Solution obj; - vvd edges1 = {{0, 1}, {0, 2}, {1, 4}, {1, 5}, {2, 3}, {2, 6}}, - edges2 = {{0, 1}, {1, 2}, {0, 3}}, - edges3 = {{0, 1}, {0, 2}, {1, 3}, {0, 4}}; - for (auto i : obj.countSubTrees(7, edges1, "abaedcd")) - cout << i << ' '; // expect: 2,1,1,1,1,1,1 - cout << endl; - for (auto i : obj.countSubTrees(4, edges2, "bbbb")) - cout << i << ' '; // expect: 4,2,1,1 - cout << endl; - for (auto i : obj.countSubTrees(5, edges3, "aabab")) - cout << i << ' '; // expect: 3,2,1,1,1 - cout << endl; -} -- cgit v1.2.3