my simple and easy-understanding solution using Java


  • 0
    J
            int next = 1;
            long sum = 0;
            int count = 0;
            while (sum < n) {
                sum += next;
                next++;
                count++;
            }
            if (sum == n) {
                return count;
            } else {
                return count - 1;
            }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.