JAVA_LeetCode 2485_Find the Pivot Integer 풀이 class Solution { public int pivotInteger(int n) { // 먼저 총합을 구한 뒤, 현재 합과 총합의 차이가 현재 정수의 2배와 같은 지 확인한다. int res = 1, sum1 = n * (n + 1) / 2, sum2 = 0; while(res <= n){ sum2 = res * (res + 1) / 2; if(sum2 == (sum1 + res - sum2)) return res; res++; } return -1; } } * 출처 https://leetcode.com/problems/find-the-pivot-integer...
JAVA_LeetCode 2485_Find the Pivot Integer에 대한 요약내용입니다.
자세한 내용은 아래에 원문링크를 확인해주시기 바랍니다.