프로그래머스/Lv.0
프로그래머스 코딩테스트 연습 Lv.0 Swift
-
import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return num1 + num2 }
[Swift] 두수의 합import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return num1 + num2 }
2022.12.14 -
import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return num1 - num2 }
[Swift] 두수의 차import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return num1 - num2 }
2022.12.14 -
import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return Int(Double(num1) / Double(num2) * 1000) }
[Swift] 두수의 나눗셈import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return Int(Double(num1) / Double(num2) * 1000) }
2022.12.14 -
import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return num1 * num2 }
[Swift] 두수의 곱import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return num1 * num2 }
2022.12.14 -
import Foundation func solution(_ my_string:String) -> String { let alph = "abcdefghijklmnopqrstuvwxyz" return my_string.map { alph.contains($0) ? String($0).uppercased() : String($0).lowercased() }.joined() }
[Swift] 대문자와 소문자import Foundation func solution(_ my_string:String) -> String { let alph = "abcdefghijklmnopqrstuvwxyz" return my_string.map { alph.contains($0) ? String($0).uppercased() : String($0).lowercased() }.joined() }
2022.12.14 -
import Foundation func solution(_ polynomial:String) -> String { let arr = polynomial.components(separatedBy: " + ") let x = arr.filter { $0.last == "x" }.map { var str = $0 str.removeLast() return str.isEmpty ? 1 : Int(str)! }.reduce(0, +) let y = arr.compactMap { Int($0) }.reduce(0, +) if x == 1 { if y == 0 { return "x" } else { return "x + \(y)" } } else if x == 0 { return "\(y)" } else if y ..
[Swift] 다항식 더하기import Foundation func solution(_ polynomial:String) -> String { let arr = polynomial.components(separatedBy: " + ") let x = arr.filter { $0.last == "x" }.map { var str = $0 str.removeLast() return str.isEmpty ? 1 : Int(str)! }.reduce(0, +) let y = arr.compactMap { Int($0) }.reduce(0, +) if x == 1 { if y == 0 { return "x" } else { return "x + \(y)" } } else if x == 0 { return "\(y)" } else if y ..
2022.12.14 -
import Foundation func solution(_ common:[Int]) -> Int { let first = common[1] - common[0] let second = common[2] - common[1] return first == second ? common.last! + first : common.last! * common[1] / common[0] }
[Swift] 다음에 올 숫자import Foundation func solution(_ common:[Int]) -> Int { let first = common[1] - common[0] let second = common[2] - common[1] return first == second ? common.last! + first : common.last! * common[1] / common[0] }
2022.12.14 -
import Foundation func solution(_ age:Int) -> Int { return 2023 - age }
[Swift] 나이 출력import Foundation func solution(_ age:Int) -> Int { return 2023 - age }
2022.12.13