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

边栏推荐
- Database course design: college educational administration management system (including code)
- How to improve the deletion speed of sequential class containers?
- Fairygui joystick
- dosbox第一次使用
- PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
- VLSM variable length subnet mask partition tips
- NRF24L01 troubleshooting
- In 2020, the average salary of IT industry exceeded 170000, ranking first
- Knowledge system of digital IT practitioners | software development methods -- agile
- Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
猜你喜欢

There is no red exclamation mark after SVN update

First use of dosbox
![[算法] 剑指offer2 golang 面试题1:整数除法](/img/e6/f17135207b3540ec58e5a9eed54220.png)
[算法] 剑指offer2 golang 面试题1:整数除法
![[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等](/img/11/ee0628a68542236fc641966579a31a.png)
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等

(1) Introduction Guide to R language - the first step of data analysis

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

Force buckle 1189 Maximum number of "balloons"

On March 15, the official version of go 1.18 was released to learn about the latest features and usage

NRF24L01 troubleshooting

FGUI工程打包发布&导入Unity&将UI显示出来的方式
随机推荐
FairyGUI人物状态弹窗
MySQL shutdown is slow
染色法判定二分图
SSD technical features
Latex learning
FairyGUI循環列錶
第一人称视角的角色移动
[leetcode622]设计循环队列
[算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
FGUI工程打包发布&导入Unity&将UI显示出来的方式
GPS高程拟合抗差中误差的求取代码实现
Fabrication d'un sac à dos simple fairygui
[算法] 剑指offer2 golang 面试题7:数组中和为0的3个数字
【RTKLIB 2.4.3 b34 】版本更新简介一
[leetcode19] delete the penultimate node in the linked list
微信小程序开发心得
Unity scene jump and exit
[Leetcode15]三数之和
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
Devops' future: six trends in 2022 and beyond