当前位置:网站首页>[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
边栏推荐
- Game 280 weekly
- It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
- NovAtel 板卡OEM617D配置步骤记录
- [算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
- [算法] 剑指offer2 golang 面试题9:乘积小于k的子数组
- SSD technical features
- 闇の連鎖(LCA+树上差分)
- rtklib单点定位spp使用抗差估计遇到的问题及解决
- Unity3D制作注册登录界面,并实现场景跳转
- Fairygui joystick
猜你喜欢
[Nodejs] 20. Koa2 onion ring model ----- code demonstration
There is no red exclamation mark after SVN update
dosbox第一次使用
[算法] 剑指offer2 golang 面试题1:整数除法
FairyGUI增益BUFF数值改变的显示
Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
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
FairyGUI简单背包的制作
【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
(1) Introduction Guide to R language - the first step of data analysis
随机推荐
341. Flatten nested list iterator
Teach you to release a DeNO module hand in hand
Matlab读取GNSS 观测值o文件代码示例
染色法判定二分图
Lean product development - Lean Software Development & lean product development
Unity3D基础入门之粒子系统(属性介绍+火焰粒子系统案例制作)
[算法] 剑指offer2 golang 面试题2:二进制加法
Liste des boucles de l'interface graphique de défaillance
Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
[offer29] sorted circular linked list
Lock wait timeout exceeded try restarting transaction
Guided package method in idea
【无标题】
FGUI工程打包发布&导入Unity&将UI显示出来的方式
NRF24L01 troubleshooting
[Leetcode15]三数之和
【rtklib】在rtk下使用抗差自适应卡尔曼滤波初步实践
[算法] 剑指offer2 golang 面试题10:和为k的子数组