분류 전체보기
-
import Foundation func solution(_ sides:[Int]) -> Int { let sides = sides.sorted() return sides[0] + sides[1] > sides[2] ? 1 : 2 }
[Swift] 삼각형의 완성조건 (1)import Foundation func solution(_ sides:[Int]) -> Int { let sides = sides.sorted() return sides[0] + sides[1] > sides[2] ? 1 : 2 }
2022.12.17 -
import Foundation func gcd(_ a: Int, _ b: Int) -> Int { if b == 0 { return a } else { return gcd (b, a % b) } } func solution(_ denum1:Int, _ num1:Int, _ denum2:Int, _ num2:Int) -> [Int] { let d = denum1 * num2 + denum2 * num1 let n = num1 * num2 let g = gcd(d, n) return [d/g, n/g] }
[Swift] 분수의 덧셈import Foundation func gcd(_ a: Int, _ b: Int) -> Int { if b == 0 { return a } else { return gcd (b, a % b) } } func solution(_ denum1:Int, _ num1:Int, _ denum2:Int, _ num2:Int) -> [Int] { let d = denum1 * num2 + denum2 * num1 let n = num1 * num2 let g = gcd(d, n) return [d/g, n/g] }
2022.12.17 -
import Foundation func solution(_ numbers:[Int]) -> Double { return Double(numbers.reduce(0, +)) / Double(numbers.count) }
[Swift] 배열의 평균값import Foundation func solution(_ numbers:[Int]) -> Double { return Double(numbers.reduce(0, +)) / Double(numbers.count) }
2022.12.17 -
import Foundation func solution(_ s1:[String], _ s2:[String]) -> Int { return s1.filter { s2.contains($0) }.count }
[Swift] 배열의 유사도import Foundation func solution(_ s1:[String], _ s2:[String]) -> Int { return s1.filter { s2.contains($0) }.count }
2022.12.17 -
import Foundation func solution(_ numbers:[Int], _ direction:String) -> [Int] { var numbers = numbers if direction == "right" { let element = numbers.removeLast() numbers.insert(element, at: 0) } else { let element = numbers.removeFirst() numbers.append(element) } return numbers }
[Swift] 배열 회전시키기import Foundation func solution(_ numbers:[Int], _ direction:String) -> [Int] { var numbers = numbers if direction == "right" { let element = numbers.removeLast() numbers.insert(element, at: 0) } else { let element = numbers.removeFirst() numbers.append(element) } return numbers }
2022.12.17 -
import Foundation func solution(_ numbers:[Int], _ num1:Int, _ num2:Int) -> [Int] { return Array(numbers[num1...num2]) }
[Swift] 배열 자르기import Foundation func solution(_ numbers:[Int], _ num1:Int, _ num2:Int) -> [Int] { return Array(numbers[num1...num2]) }
2022.12.17 -
import Foundation func solution(_ strlist:[String]) -> [Int] { return strlist.map { $0.count } }
[Swift] 배열 원소의 길이import Foundation func solution(_ strlist:[String]) -> [Int] { return strlist.map { $0.count } }
2022.12.17 -
import Foundation func solution(_ num_list:[Int]) -> [Int] { return num_list.reversed() }
[Swift] 배열 뒤집기import Foundation func solution(_ num_list:[Int]) -> [Int] { return num_list.reversed() }
2022.12.17