Test
-
func solution(_ numbers:[Int], _ k:Int) -> Int { return numbers[(k-1) * 2 % numbers.count] } 출처 [swift] 프로그래머스 - 공던지기 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 나의 풀 muker.tistory.com
[Programmers] 공 던지기func solution(_ numbers:[Int], _ k:Int) -> Int { return numbers[(k-1) * 2 % numbers.count] } 출처 [swift] 프로그래머스 - 공던지기 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 나의 풀 muker.tistory.com
2023.10.28 -
func solution(_ num_list:[Int], _ n:Int) -> [[Int]] { var result:[[Int]] = [] var cnt: Int = 0 for i in 0...((num_list.count/n)-1) { result.append((cnt...(cnt+n-1)).map{ num_list[$0] }) cnt += n } return result } 출처 [Swift] 코딩테스트 연습! Lv0. 2차원으로 만들기 /* 2차원으로 만들기 - 정수 배열 num_list와 정수 n이 매개변수로 주어집니다. num_list를 다음 설명과 같이 2차원 배열로 바꿔 return하도록 solution 함수를 완성해주세요. num_list가 [1, 2, 3, 4, 5, 6, 7, 8] 로 ..
[Programmers] 2차원으로 만들기func solution(_ num_list:[Int], _ n:Int) -> [[Int]] { var result:[[Int]] = [] var cnt: Int = 0 for i in 0...((num_list.count/n)-1) { result.append((cnt...(cnt+n-1)).map{ num_list[$0] }) cnt += n } return result } 출처 [Swift] 코딩테스트 연습! Lv0. 2차원으로 만들기 /* 2차원으로 만들기 - 정수 배열 num_list와 정수 n이 매개변수로 주어집니다. num_list를 다음 설명과 같이 2차원 배열로 바꿔 return하도록 solution 함수를 완성해주세요. num_list가 [1, 2, 3, 4, 5, 6, 7, 8] 로 ..
2023.10.25 -
func solution(_ balls:Int, _ share:Int) -> Int { if (balls == share){ return 1 } let result = factorial(balls) / factorial(balls - share) / factorial(share) return Int(NSDecimalNumber(decimal: result)) } func factorial(_ n: Int) -> Decimal{ var num: Decimal = Decimal(1) for i in 1...n { num *= Decimal(i) } return num } Int 형으로 처음에 풀다가 Demical로 변형하여 풀었더니 성공하였다. Int 형 팩토리얼(재귀함수) func factorial(_ n..
[Programmers] 구슬을 나누는 경우의 수func solution(_ balls:Int, _ share:Int) -> Int { if (balls == share){ return 1 } let result = factorial(balls) / factorial(balls - share) / factorial(share) return Int(NSDecimalNumber(decimal: result)) } func factorial(_ n: Int) -> Decimal{ var num: Decimal = Decimal(1) for i in 1...n { num *= Decimal(i) } return num } Int 형으로 처음에 풀다가 Demical로 변형하여 풀었더니 성공하였다. Int 형 팩토리얼(재귀함수) func factorial(_ n..
2023.10.24 -
func solution(_ age:Int) -> String { let str = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] return String(age).map{str[Int(String($0))!]}.joined() }
[Programmers] 외계행성의 나이func solution(_ age:Int) -> String { let str = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] return String(age).map{str[Int(String($0))!]}.joined() }
2023.10.22 -
func solution(_ num_list:[Int]) -> [Int] { var arr: [Int] = [] var tmp = num_list.reversed() for i in tmp{ arr.append(i) } return arr } reversed() 함수 사용하고 for문에서 적용하면 되는 문제...
[Programmers] 배열 뒤집기func solution(_ num_list:[Int]) -> [Int] { var arr: [Int] = [] var tmp = num_list.reversed() for i in tmp{ arr.append(i) } return arr } reversed() 함수 사용하고 for문에서 적용하면 되는 문제...
2023.10.14 -
func solution(_ array:[Int]) -> Int { var dictionary = [Int: Int]() var key = 0 var count = 0 for i in array { if dictionary.contains {$0.key == i} { dictionary[i]! += 1 } else { dictionary[i] = 1 } } for (i, j) in dictionary { if j == dictionary.values.max() { count += 1 key = i } } return count == 1 ? key : -1 }
[Programmers] 최빈값 구하기func solution(_ array:[Int]) -> Int { var dictionary = [Int: Int]() var key = 0 var count = 0 for i in array { if dictionary.contains {$0.key == i} { dictionary[i]! += 1 } else { dictionary[i] = 1 } } for (i, j) in dictionary { if j == dictionary.values.max() { count += 1 key = i } } return count == 1 ? key : -1 }
2023.10.08