import Foundation
func solution(_ my_string:String) -> Int {
var result = [String]()
my_string.components(separatedBy: " ").forEach {
let str = String($0)
if result.count < 2 {
result.append(str)
} else {
let operation = result.removeLast()
let num = result.removeLast()
var tmp = ""
switch operation {
case "+" :
tmp = String(Int(num)! + Int(str)!)
case "-" :
tmp = String(Int(num)! - Int(str)!)
default :
break
}
result.append(tmp)
}
}
return Int(result.removeLast())!
}'프로그래머스 > Lv.0' 카테고리의 다른 글
| [Swift] 문자열 밀기 (0) | 2022.12.17 |
|---|---|
| [Swift] 문자열 뒤집기 (0) | 2022.12.17 |
| [Swift] 문자 반복 출력하기 (0) | 2022.12.14 |
| [Swift] 몫 구하기 (0) | 2022.12.14 |
| [Swift] 모음 제거 (0) | 2022.12.14 |