当前位置:网站首页>[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

边栏推荐
- Minio file download problem - inputstream:closed
- PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
- [Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
- Unity3d makes the registration login interface and realizes the scene jump
- 2021.11.10汇编考试
- Idea problem record
- (4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
- Design and implementation of general interface open platform - (39) simple and crude implementation of API services
- Fairygui joystick
- What is the maximum length of MySQL varchar field
猜你喜欢

idea中导包方法

使用rtknavi进行RT-PPP测试

FairyGUI簡單背包的制作

【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现

Fabrication d'un sac à dos simple fairygui

微信小程序开发心得

(1) Introduction Guide to R language - the first step of data analysis
![[Nodejs] 20. Koa2 onion ring model ----- code demonstration](/img/a8/a4390238685903b63bb036206f8dcb.jpg)
[Nodejs] 20. Koa2 onion ring model ----- code demonstration

Unity3D,阿里云服务器,平台配置

2021.11.10 compilation examination
随机推荐
wsl常用命令
Knowledge system of digital IT practitioners | software development methods -- agile
Latex learning
【GNSS】抗差估计(稳健估计)原理及程序实现
Unity3D制作注册登录界面,并实现场景跳转
Halcon knowledge: gray_ Tophat transform and bottom cap transform
PRIDE-PPPAR源码解析
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
What are the functions and features of helm or terrain
音乐播放(Toggle && PlayerPrefs)
[算法] 剑指offer2 golang 面试题7:数组中和为0的3个数字
Force buckle 1189 Maximum number of "balloons"
[算法] 劍指offer2 golang 面試題2:二進制加法
【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
What is the maximum length of MySQL varchar field
NRF24L01 troubleshooting
[leetcode622]设计循环队列
Database table splitting strategy
Mysql database index
The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan