Skip to content

Commit ebbeddc

Browse files
refactor 724
1 parent 3b94103 commit ebbeddc

File tree

1 file changed

+8
-31
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+8
-31
lines changed

src/main/java/com/fishercoder/solutions/_724.java

+8-31
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 724. Find Pivot Index
5-
*
6-
* Given an array of integers nums, write a method that returns the "pivot" index of this array.
7-
* We define the pivot index as the index where the sum of the numbers to the left of the index is equal
8-
* to the sum of the numbers to the right of the index.
9-
* If no such index exists, we should return -1. If there are multiple pivot indexes, you should return the left-most pivot index.
10-
11-
Example 1:
12-
Input:
13-
nums = [1, 7, 3, 6, 5, 6]
14-
Output: 3
15-
Explanation:
16-
The sum of the numbers to the left of index 3 (nums[3] = 6) is equal to the sum of numbers to the right of index 3.
17-
Also, 3 is the first index where this occurs.
18-
19-
Example 2:
20-
Input:
21-
nums = [1, 2, 3]
22-
Output: -1
23-
Explanation:
24-
There is no index that satisfies the conditions in the problem statement.
25-
26-
Note:
27-
The length of nums will be in the range [0, 10000].
28-
Each element nums[i] will be an integer in the range [-1000, 1000].
29-
*/
303
public class _724 {
314
public static class Solution1 {
32-
/**Space: O(n)
33-
* Time: O(n)*/
5+
/**
6+
* Space: O(n)
7+
* Time: O(n)
8+
*/
349
public int pivotIndex(int[] nums) {
3510
if (nums == null || nums.length == 0) {
3611
return -1;
@@ -50,8 +25,10 @@ public int pivotIndex(int[] nums) {
5025
}
5126

5227
public static class Solution2 {
53-
/**Space: O(1)
54-
* Time: O(n)*/
28+
/**
29+
* Space: O(1)
30+
* Time: O(n)
31+
*/
5532
public int pivotIndex(int[] nums) {
5633
int total = 0;
5734
for (int num : nums) {

0 commit comments

Comments
 (0)