Codility/Lesson 5/Prefix Sums/PassingCars/Java
Code // you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int answer = 0;
int zeroCount = 0;
for(int i=0; i<A.length; i++) {
if(A[i] == 0) {
zeroCount++;
} else {
answer += zeroCount;
if(answer > 1_000_000_000) {
return -1;
}
}
}
return answer;
}
}
Result Report
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int answer = 0;
int zeroCount = 0;
for(int i=0; i<A.length; i++) {
if(A[i] == 0) {
zeroCount++;
} else {
answer += zeroCount;
if(answer > 1_000_000_000) {
return -1;
}
}
}
return answer;
}
}
Reference
この問題について(Codility/Lesson 5/Prefix Sums/PassingCars/Java), 我々は、より多くの情報をここで見つけました https://velog.io/@taesunny/CodilityLesson-5Prefix-SumsPassingCarsJavaテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol