-
MinAvgTwoSliceStudy/알고리즘 2018. 1. 15. 14:36
Java는 사칙연산결과가 원하는대로 안나와서
javascript로 다시 풀어봄..
function solution(A) { // write your code in JavaScript (Node.js 6.4.0) var min = 0; var minIndex = 0; for(var P = 0; P < A.length ; P++){ var sum = 0;; var avg = 0; for(var Q = P+1; Q < A.length; Q++){ console.log(">> (P, Q)" + P+ "," +Q); if(sum == 0){ sum += A[P]; } sum += A[Q]; console.log("> sum : " + sum); avg = sum / ((Q - P) + 1); console.log("> avg : " + avg); if(avg < min || min == 0){ minIndex = P; min = avg; console.log(">> call min : " + minIndex + " , " + min); } } } return minIndex; }
'Study > 알고리즘' 카테고리의 다른 글
Brackets (0) 2018.01.18 NumberOfDiscIntersections (0) 2018.01.16 MaxProductOfThree (0) 2018.01.16 Distinct (0) 2018.01.15 Triangle (0) 2018.01.15 GenomicRangeQuery (0) 2018.01.15 PassingCars (0) 2018.01.12 CountDiv (0) 2018.01.12 MaxCounters (0) 2018.01.12 MissingInteger (0) 2018.01.12 댓글