분류 전체보기
-
import Foundation func solution(_ arr1:[[Int]], _ arr2:[[Int]]) -> [[Int]] { var answer = Array(repeating: [Int](), count: arr1.count) for i in 0..
[Swift] 행렬의 곱셈import Foundation func solution(_ arr1:[[Int]], _ arr2:[[Int]]) -> [[Int]] { var answer = Array(repeating: [Int](), count: arr1.count) for i in 0..
2023.02.05 -
func solution(_ n:Int) -> Int { var f0 = 0, f1 = 1, f2 = 0 for _ in 2...n { f2 = (f0 + f1) % 1234567 f0 = f1 f1 = f2 } return f2 }
[Swift] 피보나치 수func solution(_ n:Int) -> Int { var f0 = 0, f1 = 1, f2 = 0 for _ in 2...n { f2 = (f0 + f1) % 1234567 f0 = f1 f1 = f2 } return f2 }
2023.02.05 -
import Foundation func solution(_ s:String) -> [Int] { var result = [String : Int]() var s = s s.removeFirst() s.removeLast() var tmp = s.components(separatedBy: ["{","}",","]).filter { $0 != "" } Set(tmp).map { result[$0] = 0 } tmp.forEach { result[$0]! += 1 } return result.sorted { $0.1 > $1.1 }.map { Int($0.0)! } }
[Swift] 튜플import Foundation func solution(_ s:String) -> [Int] { var result = [String : Int]() var s = s s.removeFirst() s.removeLast() var tmp = s.components(separatedBy: ["{","}",","]).filter { $0 != "" } Set(tmp).map { result[$0] = 0 } tmp.forEach { result[$0]! += 1 } return result.sorted { $0.1 > $1.1 }.map { Int($0.0)! } }
2023.02.05 -
import Foundation func solution(_ brown:Int, _ yellow:Int) -> [Int] { let sum = brown + yellow var x = 0 var y = 0 for i in 1...sum { if sum % i == 0 { x = sum / i y = i } if (x - 2)*(y - 2) == yellow { break } } return [x, y] }
[Swift] 카펫import Foundation func solution(_ brown:Int, _ yellow:Int) -> [Int] { let sum = brown + yellow var x = 0 var y = 0 for i in 1...sum { if sum % i == 0 { x = sum / i y = i } if (x - 2)*(y - 2) == yellow { break } } return [x, y] }
2023.02.05 -
import Foundation func solution(_ A:[Int], _ B:[Int]) -> Int { zip(A.sorted(), B.sorted(by: >)).map { $0 * $1 }.reduce(0, +) }
[Swift] 최솟값 만들기import Foundation func solution(_ A:[Int], _ B:[Int]) -> Int { zip(A.sorted(), B.sorted(by: >)).map { $0 * $1 }.reduce(0, +) }
2023.02.05 -
import Foundation func solution(_ s:String) -> String { let nums = s.components(separatedBy: " ").map { Int($0)! } return "\(nums.min()!) \(nums.max()!)" }
[Swift] 최댓값과 최솟값import Foundation func solution(_ s:String) -> String { let nums = s.components(separatedBy: " ").map { Int($0)! } return "\(nums.min()!) \(nums.max()!)" }
2023.02.05 -
import Foundation struct Stack { private var stack: [T] = [] public var count: Int { return stack.count } public var isEmpty: Bool { return stack.isEmpty } public mutating func push(_ element: T) { stack.append(element) } public mutating func pop() -> T? { return isEmpty ? nil : stack.popLast() } } func solution(_ s:String) -> Int{ var answer = Stack() for s in Array(s) { if !answer.isEmpty { le..
[Swift] 짝지어 제거하기import Foundation struct Stack { private var stack: [T] = [] public var count: Int { return stack.count } public var isEmpty: Bool { return stack.isEmpty } public mutating func push(_ element: T) { stack.append(element) } public mutating func pop() -> T? { return isEmpty ? nil : stack.popLast() } } func solution(_ s:String) -> Int{ var answer = Stack() for s in Array(s) { if !answer.isEmpty { le..
2023.02.05 -
import Foundation func solution(_ n:Int) -> Int { var n = n var ans:Int = 0 while 0 < n { if n % 2 != 0 { ans += 1 } n /= 2 } return ans }
[Swift] 점프와 순간 이동import Foundation func solution(_ n:Int) -> Int { var n = n var ans:Int = 0 while 0 < n { if n % 2 != 0 { ans += 1 } n /= 2 } return ans }
2023.02.05