Test/Coding Tests

func solution(_ board:[[Int]]) -> Int { var copy = board for i in 0...board.count-1 { for j in 0...board.count-1 { if board[i][j] == 1 { if i != 0 && j != 0 { if copy[i-1][j-1] != 1 { copy[i-1][j-1] = 2 } } if i != 0 { if copy[i-1][j] != 1 { copy[i-1][j] = 2 } } if i != 0 && j+1 < board.count { if copy[i-1][j+1] != 1 { copy[i-1][j+1] = 2 } } if j != 0 { if copy[i][j-1] != 1 { copy[i][j-1] = 2 } ..

func solution(_ my_string:String) -> Int { return my_string.split(whereSeparator: { !$0.isNumber }) .reduce(0) { $0 + Int($1)! } } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 참고 [프로그래머스] 숨어있는 숫자의 덧셈(2)(Swift) 코드 회고 어떻게 풀지 감이 안와 다른 사람의 코드를 보고 이해를 하였다 reduce라는 고차함수는 데이터를 합쳐주기 위해 사용하는 함수이다 map, filter, reduce 같은 고차함수들을 공부해야겠다 velog.io

var sorted: [Int] = numbers.sorted() var a: Int = sorted[0]*sorted[1] var b: Int = sorted[numbers.count-1]*sorted[numbers.count-2] return a > b ? a : b 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr

func solution(_ dots:[[Int]]) -> Int { var x = dots[0][0] - dots[1][0] != 0 ? dots[0][0] - dots[1][0] : (dots[0][0] - dots[2][0] != 0 ? dots[0][0] - dots[2][0] : dots[0][0] - dots[3][0]) var y = dots[0][1] - dots[1][1] != 0 ? dots[0][1] - dots[1][1] : (dots[0][1] - dots[2][1] != 0 ? dots[0][1] - dots[2][1] : dots[0][1] - dots[3][1]) return abs(x)*abs(y) } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그..

func solution(_ my_str:String, _ n:Int) -> [String] { var arr: [String] = [] var result = "" for i in my_str{ result += String(i) if result.count == n{ arr.append(result) result = "" } } if !result.isEmpty{ arr.append(result) } return arr } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr

func solution(_ quiz:[String]) -> [String] { var result: [String] = [] for i in quiz{ var arr = i.components(separatedBy: " ") if arr[1] == "-"{ if Int(arr[0])! - Int(arr[2])! == Int(arr[4])!{ result.append("O") } else{ result.append("X") } } else{ if Int(arr[0])! + Int(arr[2])! == Int(arr[4])!{ result.append("O") } else{ result.append("X") } } } return result } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 ..