알고리즘 문제 풀기

<스위프트&알고리즘> 10818번 최소, 최대

studying develop 2020. 4. 16. 22:45

 

둘다 정답 코드에서 갖고 온것이다.

let N = readLine()
let input = readLine()!.split(separator: " ").map() { Int(String($0))! }

var min = 1000000
var max = -1000000



for i in input {
  
  if min > i {
    min = i
    
  }
  
  if max < i {
    max = i
  }
  
}


print("\(min) \(max)")

 this got correct while the beneth it got timed out , though its on the answer board;;

 

readLine()
let a=readLine()!.split{$0==" "}.map{Int($0)!}
print("\(a.min()!) \(a.max()!)")

 

i should configure split.map mechanism;;

 

import Foundation


readLine()
let a = readLine()!.split(separator: " ")
//let b = a.map{ Int($0)! }

print("1 2")

ㅇ이렇게 해야 틀렸습니다가 뜨는걸로 보아 map이 오래걸리네; 근데 맵이 오래걸릴게 있나; 노 이해;...

 

음 맞는 코드를 보니 

let b = a.map(){ Int($0)! }

 

이렇게 map() {} 으로 되어있다. 음 근데 모르겠다. 무슨 차이지??????

 

func map<T>(_ transform: (Element) throws -> T) rethrows -> [T]

이게 명세인데,

let cast = ["Vivien", "Marlon", "Kim", "Karl"]
let lowercaseNames = cast.map { $0.lowercased() }
// 'lowercaseNames' == ["vivien", "marlon", "kim", "karl"]
let letterCounts = cast.map { $0.count }
// 'letterCounts' == [6, 6, 3, 4]

예시도 () 없는걸;; 아 이건 그냥 문법차이지, 성능 차이는 없음

 

그래서 모르겠다. 답을 내도 안되니 ; 일단 질문중임