Title description
Short-circuit of solution and operation
A && B, if the value of A statement is false/0, B will not be executed . It was used in the judgment before, only to find that it can be a single sentence
class Solution {
public:
int sumNums(int n) {
int ans = 0;
n && (ans = sumNums(n - 1) + n);
return ans;
}
};
Time complexity O(N)
Space complexity O(N)