979. Distribute Coins in Binary Tree 一次過有點意外 不過我也只寫得動medium了== 從leaf node 算盈餘 每多一個或少一個都要移動硬幣 class Solution { public: int distributeCoins(TreeNode* root) { int ans = 0; dfs(root, ans); return ans; } int dfs(TreeNode* root, int &ans){ if(root == nullptr) return 0; int left = dfs(root->left, ans); int right = dfs(root->right, ans); ans += abs(left) + abs(right); return left + right + root->val - 1; } }; 話說我想開始學rust有人有建議ㄇ -- ※ 發信站: 批踢踢實業坊(ptt-website.tw), 來自: 114.36.45.115 (臺灣) ※ 文章網址: https://ptt-website.tw/Marginalman/M.1715996559.A.672
steven183: 別卷了 05/18 09:43
sustainer123: @yam @教授 05/18 09:45
wu10200512: 別卷了 05/18 09:47
argorok: 別卷了 05/18 09:49
ILoveErr: 大師 05/18 09:53
wiimas: 包養輕鬆找到興趣相投的朋友。 05/18 09:53