-
724. Find Pivot Index javaLeetCode_Study_Plan/LeetCode 75 2022. 9. 25. 17:13
https://leetcode.com/problems/find-pivot-index/?envType=study-plan&id=level-1
class Solution { public int pivotIndex(int[] nums) { int pivot = 0; int total_sum = Arrays.stream(nums).sum(); for(int i = 0; i < nums.length; i++){ int tmp_sum = 0; for (int j = 0; j < i ; j++){ tmp_sum += nums[j]; } // System.out.println("i: " + i + " tmp_sum: " + tmp_sum); if (tmp_sum == total_sum - tmp_sum - nums[i]){ pivot = i; return pivot; }; } return -1; } }
'LeetCode_Study_Plan > LeetCode 75' 카테고리의 다른 글
206. Reverse Linked List java (0) 2022.10.05 392. Is Subsequence java (0) 2022.10.04 [LeetCode 75] 중간 점검 (0) 2022.10.02 205. Isomorphic Strings java (0) 2022.09.26 1480. Running Sum of 1d Array java (0) 2022.09.25