21. Reverse Coding
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
int mod = 1e9 + 7;
int sumOfNaturals(int n) {
long long sum = n;
sum = (sum * (sum + 1)) % mod;
sum /= 2;
return sum;
}
};Contribution and Support
Last updated