-
[프로그래머스 level.1] 이중반복문, 중복제거, 정렬알고리즘 2023. 6. 20. 11:18
두개를 뽑아서 더하기
function solution(numbers) { let answer = []; for (let i = 0; i < numbers.length; i++) { for(let j = i + 1; j < numbers.length; j++) { answer.push(numbers[i] + numbers[j]); } } let result = [...new Set(answer)].sort(function(a, b) {return a - b;}); return result; }
set을 활용하는것에 대해 선언을 간단하게 저렇게도 할 수 있다는 것을 알게 되었음 객체를 변수에 꼭 저장하지 않아도 호출만으로도 사용하는 법이 있구나 싶었음
sort() 관련되서는 항상 헷갈림 안에 수 정의를 하는 func를 넣어야 하는데 이번에 또 까먹어서 다시 찾아보게 되었다
이중반복문으 쓰기 싫은데 풀고나서 다른사람들 풀이보니까 다 쓰고있어서 답이 없는것 같다.
'알고리즘' 카테고리의 다른 글
[프로그래머스 level.1] slice 스파르타 예습 (0) 2023.06.20 [프로그래머스 level.1] filter , includes (0) 2023.06.20 [프로그래머스 level.1] 06.19 (0) 2023.06.19 알고리즘 Day-1 (0) 2023.06.16 알고리즘 & 자료구조 스터디(10조) 8일차 (0) 2023.05.30