From 28542a33ef2fb5c345faef8dc9648cc7abe8f5c1 Mon Sep 17 00:00:00 2001 From: zeekling Date: Sun, 16 Aug 2020 14:57:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BB=E6=89=BE=E6=95=B0=E7=BB=84=E7=9A=84?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- src/list/PivotIndex.java | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/list/PivotIndex.java diff --git a/.gitignore b/.gitignore index 30eed9a..5ba13b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ target .idea - +*.swp diff --git a/src/list/PivotIndex.java b/src/list/PivotIndex.java new file mode 100644 index 0000000..f8e0c2e --- /dev/null +++ b/src/list/PivotIndex.java @@ -0,0 +1,39 @@ +package list; + + +/** + * @file PivotIndex.java + * @apiNote https://leetcode-cn.com/leetbook/read/array-and-string/yf47s/ + * @author zeekling + * @version 1.0 + * @date 2020-08-16 + */ +public class PivotIndex { + + + public int pivotIndex(int[] nums){ + int sum = 0; + int len = nums.length; + for (int i=0; i< len;i++){ + sum += nums[i]; + } + int idx = -1; + int leftSum = 0; + for (int i=0;i