Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes. For example, in an arrya A:
A[0] = -7, A[1] = 1, A[2] = 5, A[3] = 2, A[4] = -4, A[5] = 3, A[6]=0
3 is an equilibrium index, because:
A[0] + A[1] + A[2] = A[4] + A[5] + A[6]
6 is also an equilibrium index, because sum of zero elements is zero, i.e., A[0] + A[1] + A[2] + A[3] + A[4] + A[5]=0
7 is not an equilibrium index, because it is not a valid index of array A.
Write a function int equilibrium(int[] arr, int n); that given a sequence arr[] of size n, returns an equilibrium index (if any) or -1 if no equilibrium indexes exist.
public int equilIndex(int[] A) { int sum = 0; for(int num:A) { sum += num; } int left = 0; for(int i=0; i<A.length; i++) { sum -= A[i]; if(sum == left) { return i; } left += A[i]; } return -1; }
Reference:
相关推荐
Effect of prey refuge on the dynamics and equilibrium density of,马智慧,李自珍,In this paper, we use an analytical approach to study the dynamics of the simplest forms of refuge using by prey....
Equilibrium
平衡点外模式形成pattern formation outside of equilibrium平衡点外模式形成pattern formation outside of equilibrium平衡点外模式形成pattern formation outside of equilibrium平衡点外模式形成pattern ...
is a proposed solution of a non-cooperative game involving two or more players in which each player is assumed to know the equilibrium strategies of the other players, and no player has anything to ...
The problem is to find the equilibrium point of a static market model
Fundamentals of Power Electronics 第一部分 PartⅠ Converters in Equilibrium PPT
Equilibrium in a Capital Asset Market.pdfEquilibrium in a Capital Asset Market.pdf
Abstract-One way to alleviate the heavy computation required by simulated annealing placement algorithms ...is also used to give an interesting view of the equilibrium dynamics of simulated annealing.
3.7 Statistical Mechanics of an Ideal Monatomic Gas 3.8 Statistical Mechanics in the Presence of Gravity: Galaxies, Black Holes, the Universe, and Evolution of Structure in the Early Universe 3.9 ...
4.3.1 Equilibrium Concentration of Point Defects 256 4.3.2 Production of Point Defects 259 4.3.3 Effect of Point Defects on Mechanical Properties 260 4.3.4 Radiation Damage 261 4.3.5 Ion Implantation ...
Market Structure and Equilibrium 经济学 与 博弈的老书
Method of Unstable Equilibrium Point Control of Chaotic System with Unmeasured State Variables
用CEA进行火箭发动机的热力计算,可以进行化学组分平衡的热力计算
随机多目标均衡约束规划问题,林贵华,,本文主要研究随机多目标均衡约束问题,给出了几个Patrto 稳定点条件。本文还把Pareto 稳定点条件转化为比较容易求解的混合互补问题。�
考虑人力资本内生性增长的均衡搜寻模型,唐万生,周驰,研究了一个均衡搜寻问题,其中公司提供的工作机会是技能和非技能的,而工人由于教育水平的不同分为高学历和低学历的.工作机会的结构
淡化后浓海水制备液体盐过程中除溴工艺及溴的平衡浓度的研究,郭晓俊,袁俊生,本文对海水淡化浓海水除溴制备液体盐的工艺条件进行了研究,同时,分析了浓海水中溴的平衡与操作温度和操作压力的关系。...
Part IV describes the evidence on classical game theory and considers several models of behavioral game theory, including level-k and cognitive hierarchy models, quantal response equilibrium, and ...
具有完全替代品的并发二价拍卖下的对称贝叶斯-纳什均衡,卜天明,祁琦,本文研究了同时存在两个单轮密闭二价拍卖的模型。在该模型下,每个拍卖商卖同一件商品。每个竞拍者只愿意得到一件商品。该模型来
变分不等式在网络均衡问题中的相关应用(F.GIANNESSI and A.MAUGERI)
1 Application of GATES and MATLAB for Resolution of Equilibrium, Metastable and Non-Equilibrium Electrolytic Systems 2 From Discrete to Continuous Gene Regulation Models – A Tutorial Using the Odefy ...