## [EAZY] - TapeEquilibrium 原

dkf_genius

 Task description A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1]. The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])| In other words, it is the absolute difference between the sum of the first part and the sum of the second part. For example, consider array A such that: ``````A[0] = 3 A[1] = 1 A[2] = 2 A[3] = 4 A[4] = 3`````` We can split this tape in four places: P = 1, difference = |3 − 10| = 7  P = 2, difference = |4 − 9| = 5  P = 3, difference = |6 − 7| = 1  P = 4, difference = |10 − 3| = 7  Write a function: class Solution { public int solution(int[] A); } that, given a non-empty zero-indexed array A of N integers, returns the minimal difference that can be achieved. For example, given: ``````A[0] = 3 A[1] = 1 A[2] = 2 A[3] = 4 A[4] = 3`````` the function should return 1, as explained above. Assume that: N is an integer within the range [2..100,000]; each element of array A is an integer within the range [−1,000..1,000]. Complexity: expected worst-case time complexity is O(N); expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments). Elements of input arrays can be modifie
``````class Solution {
public int solution(int[] A) {
// write your code in Java SE 8

if (A == null || A.length < 2 || A.length > 100000) {
return 0;
}

if (A.length == 2) {
return Math.abs(A[0] - A[1]);
}

int leftSum = A[0];
int rightSum = 0;

for (int j=1; j<A.length; j++) {
rightSum += A[j];
}

int minDiff = Math.abs(leftSum - rightSum);

for (int i=1; i<A.length-1; i++) {
leftSum += A[i];
rightSum -= A[i];
int diff = Math.abs(leftSum - rightSum);
if (diff < minDiff) {
minDiff = diff;
}
}

return minDiff;
}
}``````

### dkf_genius

win7 64位 scrapy安装

scrapy的安装不难 就是挺麻烦的，需要安装scrapy的一些依赖包，我以我的机子环境为例说明一些安装过程 系统：win7 64bit 安装步骤： 1.先安装Python，机子是64位的，所以Python最好安装64位的...

Airship
2015/12/13
34
0

okgo2010
2011/04/13
334
0

okgo2010
2011/02/22
5.8K
14

okgo2010
2011/03/04
1K
21
R语言，python接口rpy2安装的问题

2012/03/16
4.2K
5

7个习惯提升python效率

1. 使用本地变量 尽量使用局部变量，避免使用全局变量 2.减少函数调用 (1)当我们判断对象的类别的时候，尽量使用isinstance()，其次使用id()，最不济使用type()   type(num)==type(0) type(...

10分钟前
2
0
mongodb使用

【mongodb全库备份:】 #cd /usr/local/mongodb/bin # ./mongodump 则会在当前目录生成一个dump目录，整个库会备份在这个目录下。 【指定数据库备份】 # ./mongodump -h localhost -d Hawkey...

14分钟前
1
0
hive count distinct和group by

18分钟前
1
0
day180-2018-12-17-英语流利阅读-待学习

“黄马甲”再上巴黎街头，马克龙成为众矢之的 毛西 2018-12-17 1.今日导读 圣诞将至，但此时的法国人都在担心周六的到来，因为巴黎的“黄背心”抗议活动已经连续进行了四周，举国上下人心惶惶...

20分钟前
7
0
Deepin 下安装 Docker

Docker官网上并没有提供关于 Deepin 的 Docker 安装教程，由于 Deepin 是基于 Debian 的，所以可以参照官网 Debian的安装教程安装，但 Deepin 在定制过程中进行了大量修改，所以使用官方教程...

22分钟前
1
0