作者SecondRun (南爹摳打)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Mon Apr 15 17:30:49 2024
129.
求路徑上的數字字串合
C# code
public class Solution {
public int SumNumbers(TreeNode root, int num = 0)
{
if (root == null) return 0;
num = num * 10 + root.val;
if (root.left == null && root.right == null) return num;
return SumNumbers(root.left, num) + SumNumbers(root.right, num);
}
}
--
(づ′・ω・)づ
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.220.51.52 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1713173453.A.0CA.html
推 DJYOSHITAKA: 大濕 04/15 17:31
→ sustainer123: 大師 04/15 17:31
推 JIWP: 大師 04/15 17:40
→ digua: 大師 04/15 17:44