티스토리 뷰
Solution in JavaScript
const arr = [3, 10, 2, 9];
const k = 1;
const b = 12;
function solve(bill, k, b) {
bill[k] = 0; // 해당 index를 제외하고 시작.
let sum = bill.reduce((x,y) => x + y); // reduce로 전부 sum
let each = sum / 2;
if(each === b){
console.log('Bon Appetit');
} else {
console.log(b - each);
}
}
solve(arr, k, b);
//loop해서 k의 index를 제외하는 것 -> 해당 index에 0을 넣기.(이 생각을 내가 왜 못했을까!)
Reference
'Algorithms' 카테고리의 다른 글
Cats and a Mouse (0) | 2020.09.17 |
---|---|
Find Digits (0) | 2020.09.13 |
Birthday Chocolate (0) | 2020.09.11 |
Divisible Sum Pairs (0) | 2020.09.05 |
Breaking the Records (0) | 2020.09.04 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 프로그래머스 알고리즘문제
- equals()
- spring boot application
- Javascript Algorithm
- rest parameter
- substring()
- code refactoring
- ... in Javascript
- easy javascript algorithm
- math.abs
- 프로그래머스 알고리즘
- algorithm
- hackerrank javascript
- compareTo()
- Object type casting
- C++
- hackerrank
- string class in java
- repeat()
- math.max
- easy algorithm
- java
- Collection Framework
- javascript
- hackerrank solution
- hackerrank javascript solution
- 프로그래머스
- 알고리즘
- HackerRank Algorithm
- HashMap
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함