티스토리 뷰
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
- math.max
- math.abs
- spring boot application
- string class in java
- 알고리즘
- javascript
- java
- 프로그래머스 알고리즘문제
- 프로그래머스 알고리즘
- equals()
- Collection Framework
- algorithm
- C++
- 프로그래머스
- hackerrank javascript
- easy algorithm
- code refactoring
- Javascript Algorithm
- Object type casting
- hackerrank javascript solution
- ... in Javascript
- substring()
- hackerrank solution
- repeat()
- HackerRank Algorithm
- hackerrank
- HashMap
- easy javascript algorithm
- compareTo()
- rest parameter
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
글 보관함