목록티스토리 포스트 (226)
Where who wants to meet someone
문제https://school.programmers.co.kr/learn/courses/30/lessons/12943 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 내 답안 / 다른 사람들의 답안func solution(_ num:Int) -> Int { return collatz(num)}func collatz(_ num: Int, count: Int = 0) -> Int { if num == 1 { return count } if count > 500 { return -1 } return collatz(num % 2 == 0 ? n..
문제https://school.programmers.co.kr/learn/courses/30/lessons/12910?language=swift 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 내 답안 / 다른 사람들의 답안func solution(_ arr:[Int], _ divisor:Int) -> [Int] { return arr.contains { $0 % divisor == 0 } ? arr.filter { $0 % divisor == 0 }.sorted() : [-1]}- arr에 divisor로 나눠지는 값이 있는지 체크한 다음에 있다면 f..
문제https://school.programmers.co.kr/learn/courses/30/lessons/86051 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 내 답안 / 다른 사람들의 답안import Foundationfunc solution(_ numbers:[Int]) -> Int { return (0...9).filter { !numbers.contains($0) }.reduce(0, +)}- 0부터 9까지 들어있는 범위에서 numbers에 포함되지 않은 수를 구해 더해주는 방법을 떠올릴 수 있었다. // 풀이 1func solution(..
문제https://school.programmers.co.kr/learn/courses/30/lessons/76501 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 내 답안 / 다른 사람들의 답안import Foundationfunc solution(_ absolutes:[Int], _ signs:[Bool]) -> Int { return absolutes.enumerated().map { signs[$0.offset] == true ? $0.element : -$0.element }.reduce(0, +)}- offset을 가지고 양수 음수를 판별해..
문제https://school.programmers.co.kr/learn/courses/30/lessons/12919 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 내 답안 / 다른 사람들의 답안func solution(_ seoul:[String]) -> String { return "김서방은 \(seoul.firstIndex{ $0 == "Kim" }!)에 있다"}- Kim 은 한 번만 나오고 무조건 있다는 전제가 있기 때문에 firstIndex를 사용해서 문제를 풀 수 있었다. // 풀이 1func solution(_ seoul:[String])..