Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb614e8d

Browse files
add 1991
1 parenteee5a93 commitb614e8d

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

‎README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1992|[Find All Groups of Farmland](https://leetcode.com/problems/find-all-groups-of-farmland/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1992.java)||Medium||
12+
|1991|[Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1991.java)||Easy||
1113
|1985|[Find the Kth Largest Integer in the Array](https://leetcode.com/problems/find-the-kth-largest-integer-in-the-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1985.java)||Medium||
1214
|1984|[Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1984.java)||Easy||
1315
|1981|[Minimize the Difference Between Target and Chosen Elements](https://leetcode.com/problems/minimize-the-difference-between-target-and-chosen-elements/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1981.java)||Medium|DP|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1991 {
4+
publicstaticclassSolution1 {
5+
publicintfindMiddleIndex(int[]nums) {
6+
intmiddleIndex = -1;
7+
longsum =0;
8+
for (inti =0;i <nums.length;i++) {
9+
sum +=nums[i];
10+
}
11+
longleftSum =0;
12+
for (inti =0;i <nums.length;i++) {
13+
sum -=nums[i];
14+
if (i >0) {
15+
leftSum +=nums[i -1];
16+
}
17+
if (sum ==leftSum) {
18+
returni;
19+
}
20+
}
21+
returnmiddleIndex;
22+
}
23+
}
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1991;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1991Test {
10+
privatestatic_1991.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1991.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(3,solution1.findMiddleIndex(newint[]{2,3, -1,8,4}));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp