본문 바로가기

Test/Coding Tests

(51)
[Programmers] 이어 붙인 수 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 내 풀이import Foundationfunc solution(_ num_list:[Int]) -> Int { var odd: String = "" var even: String = "" for i in 0.. 다른 사람의 풀이import Foundationfunc solution(_ numList: [Int]) -> Int { return Int(numList.filter { $0 % 2 != 0 }.map { String($0) }.joined())! + Int(numList.fi..
[BaekJoon] 15552 빠른 A+B import Foundationfinal class FileIO { private var buffer:[UInt8] private var index: Int init(fileHandle: FileHandle = FileHandle.standardInput) { buffer = Array(fileHandle.readDataToEndOfFile())+[UInt8(0)] // 인덱스 범위 넘어가는 것 방지 index = 0 } @inline(__always) private func read() -> UInt8 { defer { index += 1 } return buffer.withUnsafeBufferP..
[Programmers] 등차수열의 특정한 항만 더하기 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 내 풀이import Foundationfunc solution(_ a:Int, _ d:Int, _ included:[Bool]) -> Int { var result = 0 if(included[0] == true){ result += a } for i in 1..  다른 사람의 풀이import Foundationfunc solution(_ a: Int, _ d: Int, _ included: [Bool]) -> Int { return included.i..
[Programmers] 연속된 수의 합 func solution(_ num:Int, _ total:Int) -> [Int] { var answer = [Int]() var mid = total/num var n = num/2 if num%2 == 0{ answer = Array(mid-n+1...mid+n) } else{ answer = Array(mid-n...mid+n) } return answer } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 참고 [프로그래머스 LV.0] 연속된 수의 합 프로그래머스 LV.0 모음 연속된 수의 합 문제 설명 연속된 세 개의 정수를 더해 12가 되는 경..
[Programmers] 이진수 더하기 func solution(_ bin1:String, _ bin2:String) -> String { var a = Int(bin1, radix: 2)! var b = Int(bin2, radix: 2)! return String(a+b, radix: 2) } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr
[Programmers] 치킨 쿠폰 func solution(_ chicken:Int) -> Int { var cnt = 0 var num = chicken while num >= 10 { cnt += num / 10 num = num / 10 + num % 10 } return cnt } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr
[Programmers] 등수 매기기 func solution(_ score:[[Int]]) -> [Int] { var avg = [Int]() for i in score{ avg.append(i.reduce(0){ ($0 + $1)}) } var sorted = avg.sorted(by: >) return avg.map { (sorted.firstIndex(of:$0) ?? 0)+1 } } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr
[Programmers] 유한소수 판별하기 func solution(_ a:Int, _ b:Int) -> Int { var num:Int = b/gcd(a,b) while num % 2 == 0 { num /= 2 } while num % 5 == 0 { num /= 5 } return num == 1 ? 1 : 2 } func gcd(_ a: Int, _ b: Int) -> Int{ if b == 0 { return a } else{ return gcd(b, a % b) } } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr