// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let allPair = 0;
let count = 0;
for(let i in A){
if(A[i] == 0){
count++;
}else{
allPair += count;
}
}
if(allPair > 1000000000){
return -1
}else{
return allPair
}
}
0만 카운팅해주면 된다.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let allPair = 0
for(let i in A){
if (A[i] == 0){
let list = A.slice(i);
let count = list.filter(x => 1 === x).length;
allPair += count;
}
}
if(allPair > 1000000000){
return -1
}else{
return allPair
}
}
def solution(A):
result = 0
count_zero = 0
for i in A:
if i == 1 and count_zero == 0:
continue
elif i == 0:
count_zero += 1
elif i == 1:
result += count_zero
if result > 1000000000:
return -1
return result