当前位置:网站首页>[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
2022-07-06 12:51:00 【Deng Jiawen jarvan】
[ Algorithm ] The finger of the sword offer2 golang Interview questions 12: The sum of the left and right subarrays is equal
subject 1:

Ideas 1:
// Ideas :
//1. Record the total number sum
//2. Traversal element calculation sum - nums[i] - leftSum == leftSum ,return i
Code
func pivotIndex(nums []int) int {
//start: 13.16 end: 13.22
// Ideas :
//1. Record the total number sum
//2. Traversal element calculation sum - nums[i] - leftSum == leftSum ,return i
// Processing parameters
if len(nums) == 0 {
return -1
}
//1. Record the total number sum
sum := 0
for i := 0; i < len(nums); i++{
sum += nums[i]
}
//2. Traverse the element to find the center point
leftSum := 0
for i := 0; i < len(nums); i++{
//(1) Judge
if sum - nums[i] - leftSum == leftSum{
return i
}
// Fail to judge
leftSum += nums[i]
}
return -1
}
test

边栏推荐
- (课设第一套)1-5 317号子任务 (100 分)(Dijkstra:重边自环)
- Force buckle 1189 Maximum number of "balloons"
- PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
- Unity3d makes the registration login interface and realizes the scene jump
- [offer9]用两个栈实现队列
- FairyGUI增益BUFF数值改变的显示
- 2022国赛Re1 baby_tree
- 染色法判定二分图
- 音乐播放(Toggle && PlayerPrefs)
- 【无标题】
猜你喜欢
![[算法] 剑指offer2 golang 面试题10:和为k的子数组](/img/63/7422489d09a64ec9f0e79378761bf1.png)
[算法] 剑指offer2 golang 面试题10:和为k的子数组

The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25

(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart

2021.11.10 compilation examination

There is no red exclamation mark after SVN update

Combination of fairygui check box and progress bar

KF UD分解之UD分解基础篇【1】

基本Dos命令

FairyGUI按钮动效的混用

(core focus of software engineering review) Chapter V detailed design exercises
随机推荐
FairyGUI增益BUFF数值改变的显示
地球围绕太阳转
堆排序【手写小根堆】
基本Dos命令
Comparative analysis of the execution efficiency of MySQL 5.7 statistical table records
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
【GNSS】抗差估计(稳健估计)原理及程序实现
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
idea问题记录
Lock wait timeout exceeded try restarting transaction
Knowledge system of digital IT practitioners | software development methods -- agile
The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25
[算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
Fabrication d'un sac à dos simple fairygui
[leetcode622] design circular queue
1041 be unique (20 points (s)) (hash: find the first number that occurs once)
抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
MySQL performance tuning - dirty page refresh
How to reduce the shutdown time of InnoDB database?
isEmpty 和 isBlank 的用法区别