Re: [閒聊] 每日leetcode已回收
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
推
04/15 17:31,
1年前
, 1F
04/15 17:31, 1F
→
04/15 17:31,
1年前
, 2F
04/15 17:31, 2F
推
04/15 17:40,
1年前
, 3F
04/15 17:40, 3F
→
04/15 17:44,
1年前
, 4F
04/15 17:44, 4F
討論串 (同標題文章)
完整討論串 (本文為第 121 之 1548 篇):