Skip to content

Commit 2871a17

Browse files
committed
一刷724
1 parent dada296 commit 2871a17

File tree

8 files changed

+77
-10
lines changed

8 files changed

+77
-10
lines changed

README.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5093,14 +5093,14 @@ TIP: **公众号的微信号是: `jikerizhi`**。__因为众所周知的原因
50935093
//|{doc_base_url}/0723-candy-crush.adoc[题解]
50945094
//|Medium
50955095
//|
5096-
//
5097-
//|{counter:codes}
5098-
//|{leetcode_base_url}/find-pivot-index/[724. Find Pivot Index^]
5099-
//|{source_base_url}/_0724_FindPivotIndex.java[Java]
5100-
//|{doc_base_url}/0724-find-pivot-index.adoc[题解]
5101-
//|Easy
5102-
//|
5103-
//
5096+
5097+
|{counter:codes}
5098+
|{leetcode_base_url}/find-pivot-index/[724. Find Pivot Index^]
5099+
|{source_base_url}/_0724_FindPivotIndex.java[Java]
5100+
|{doc_base_url}/0724-find-pivot-index.adoc[题解]
5101+
|Easy
5102+
|
5103+
51045104
//|{counter:codes}
51055105
//|{leetcode_base_url}/split-linked-list-in-parts/[725. Split Linked List in Parts^]
51065106
//|{source_base_url}/_0725_SplitLinkedListInParts.java[Java]

docs/0000-03-prefix-sum.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
. xref:0303-range-sum-query-immutable.adoc[303. Range Sum Query - Immutable]
99
. xref:0304-range-sum-query-2d-immutable.adoc[304. Range Sum Query 2D - Immutable]
1010
. xref:0437-path-sum-iii.adoc[437. Path Sum III]
11+
. xref:0238-product-of-array-except-self.adoc[238. Product of Array Except Self]
12+
. xref:0724-find-pivot-index.adoc[724. Find Pivot Index]
1113

1214
== 参考资料
1315

docs/0238-product-of-array-except-self.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ include::{sourcedir}/_0238_ProductOfArrayExceptSelf_2.java[tag=answer]
4545
--
4646
====
4747

48+
该题的思路也适用于 xref:0724-find-pivot-index.adoc[724. Find Pivot Index]。
49+
4850
== 参考资料
4951

5052
. https://leetcode.cn/problems/product-of-array-except-self/solutions/11472/product-of-array-except-self-shang-san-jiao-xia-sa/?envType=study-plan-v2&envId=selected-coding-interview[238. 除自身以外数组的乘积 - 清晰图解^]

docs/0724-find-pivot-index.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,38 @@ There is no index that satisfies the conditions in the problem statement.
4444

4545

4646

47+
== 思路分析
4748

49+
这道题的技巧和 xref:0238-product-of-array-except-self.adoc[238. Product of Array Except Self] 类似。
4850

51+
image::images/0724-01.gif[{image_attr}]
52+
53+
看答案,也可以直接求和,然后在依次相加减得到两边的和。
4954

5055
[[src-0724]]
56+
[tabs]
57+
====
58+
一刷::
59+
+
60+
--
5161
[{java_src_attr}]
5262
----
5363
include::{sourcedir}/_0724_FindPivotIndex.java[tag=answer]
5464
----
65+
--
66+
67+
// 二刷::
68+
// +
69+
// --
70+
// [{java_src_attr}]
71+
// ----
72+
// include::{sourcedir}/_0724_FindPivotIndex_2.java[tag=answer]
73+
// ----
74+
// --
75+
====
76+
77+
== 参考资料
78+
79+
. https://leetcode.cn/problems/find-pivot-index/solutions/1645928/by-jyd-9265/?envType=study-plan-v2&envId=selected-coding-interview[724. 寻找数组的中心下标 - 前缀和,清晰图解^]
80+
5581

docs/images/0724-01.gif

15.4 MB
Loading

docs/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ include::0714-best-time-to-buy-and-sell-stock-with-transaction-fee.adoc[leveloff
15221522

15231523
// include::0723-candy-crush.adoc[leveloffset=+1]
15241524

1525-
// include::0724-find-pivot-index.adoc[leveloffset=+1]
1525+
include::0724-find-pivot-index.adoc[leveloffset=+1]
15261526

15271527
// include::0725-split-linked-list-in-parts.adoc[leveloffset=+1]
15281528

logbook/202406.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@
533533
|{counter:codes}
534534
|{leetcode_base_url}/product-of-array-except-self/[238. Product of Array Except Self^]
535535
|{doc_base_url}/0238-product-of-array-except-self.adoc[题解]
536-
|从后及从前,在一个数组上分两次进行计算
536+
|✅ 前缀和,从后及从前,在一个数组上分两次进行计算
537537

538538
|{counter:codes}
539539
|{leetcode_base_url}/partition-list/[86. Partition List^]
@@ -691,6 +691,13 @@
691691
|{doc_base_url}/0006-zigzag-conversion.adoc[题解]
692692
|❌ 注意审题,看题!
693693

694+
695+
|{counter:codes}
696+
|{leetcode_base_url}/find-pivot-index/[724. Find Pivot Index^]
697+
|{doc_base_url}/0724-find-pivot-index.adoc[题解]
698+
|✅ 前缀和
699+
700+
694701
|===
695702

696703
截止目前,本轮练习一共完成 {codes} 道题。
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.diguage.algo.leetcode;
2+
3+
public class _0724_FindPivotIndex {
4+
// tag::answer[]
5+
6+
/**
7+
* @author D瓜哥 · https://www.diguage.com
8+
* @since 2024-09-18 21:45:49
9+
*/
10+
public int pivotIndex(int[] nums) {
11+
int length = nums.length;
12+
int[] dp = new int[length + 2];
13+
for (int i = length; i > 0; i--) {
14+
dp[i] = nums[i - 1] + dp[i + 1];
15+
}
16+
for (int i = 1; i <= length; i++) {
17+
if (dp[i - 1] == dp[i + 1]) {
18+
return i - 1;
19+
}
20+
dp[i] = nums[i - 1] + dp[i - 1];
21+
}
22+
return -1;
23+
}
24+
25+
// end::answer[]
26+
public static void main(String[] args) {
27+
new _0724_FindPivotIndex()
28+
.pivotIndex(new int[]{-1, -1, 0, 0, -1, -1});
29+
}
30+
}

0 commit comments

Comments
 (0)