public class Solution { public int Sum_Solution(int n) { int ans = n; //短路操作 //if ans == 0 后面不执行,语句结束,相当于递归有了个终止条件,ans = 0,非常nice
// sum(n) = n+sum(n-1)
ans && (ans += Sum_Solution(n - 1)); return ans; } }
public class Solution { public int Sum_Solution(int n) { int ans = n; //短路操作 //if ans == 0 后面不执行,语句结束,相当于递归有了个终止条件,ans = 0,非常nice
// sum(n) = n+sum(n-1)
ans && (ans += Sum_Solution(n - 1)); return ans; } }