티스토리 뷰
Solution in JavaScript
const arr = [1, 3, 2, 6, 1, 2];
const k = 3;
const n = arr.length;
function Divisible_Sum_Pairs(n, k, ar) {
let num = 0;
for(let i = 0; i < n; i++) {
//condition 'i < j' 는 i보다 j가 index number로서 우선할 수 없다는 의미지 값이 커야한다는 의미가 아님.
//문제 제대로 읽기!
for(let j = (i + 1); j < n; j++){
if((ar[i] + ar[j]) % k === 0){ // 계산순서위한 () 잊지말것.
++num;
}
}
}
console.log(num);
}
Divisible_Sum_Pairs(n, k, arr);
Reference
'Algorithms' 카테고리의 다른 글
Bon Appétit (0) | 2020.09.12 |
---|---|
Birthday Chocolate (0) | 2020.09.11 |
Breaking the Records (0) | 2020.09.04 |
Apple and Orange (0) | 2020.08.24 |
Grading Students (0) | 2020.08.22 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- easy algorithm
- javascript
- rest parameter
- algorithm
- HackerRank Algorithm
- 프로그래머스 알고리즘문제
- hackerrank javascript
- hackerrank javascript solution
- HashMap
- math.abs
- hackerrank solution
- 프로그래머스 알고리즘
- compareTo()
- spring boot application
- equals()
- easy javascript algorithm
- C++
- math.max
- string class in java
- repeat()
- ... in Javascript
- Javascript Algorithm
- java
- code refactoring
- 프로그래머스
- Collection Framework
- substring()
- hackerrank
- Object type casting
- 알고리즘
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함