๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป iOSun
article thumbnail

๋ฌธ์ œ ์„ค๋ช…

 

๋ฌธ์ œ ํ’€์ด

๋‹จ์ˆœํ•œ ๊ตฌํ˜„๋ฌธ์ œ๋‹ค. ํ•ต์‹ฌ์€ 1๋‹ฌ์— 29์ผ์ด๋ผ๋Š” ์  ๊ฐ™๋‹ค.

 

๋‚ ์งœ๋ฅผ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์„œ ํ•ด๊ฒฐํ–ˆ๋‹ค.

 

ex) 2021.10.21 ์ผ ๋•Œ

(2021 * 29 * 12) + (10 * 29) + (21)

 

์ฝ”๋“œ


func solution(_ today:String, _ terms:[String], _ privacies:[String]) -> [Int] {
    
    // ๋…„๋„๋ฅผ ์ •์ˆ˜๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” ํ•จ์ˆ˜ ex) 2021.02.05 -> 2021*29*12 + 2*29 + 5
    func dateToInt(_ date: String) -> Int {
        let split = date.split(separator: ".").map {Int(String($0))!}
        return (split[0]*12*29)+(split[1]*29)+split[2]
    }
    
    var dict: [String: Int] = [:]
    let today = dateToInt(today)
    var answer: [Int] = []
    
    // ex) A: 5, B: 3
    for term in terms {
        let split = term.split(separator: " ").map {String($0)}
        dict[split[0]] = Int(split[1])!
    }
   
    for i in 0..<privacies.count {
        let split = privacies[i].split(separator: " ").map {String($0)}
        let date = dateToInt(split[0]) + dict[split[1]]!*29
        
        // ์œ ํšจ๊ธฐ๊ฐ„ ์ง€๋‚ฌ์œผ๋ฉด 
        if today >= date {
            answer.append(i+1)
        }
    }
    return answer
}

 

ํ›„๊ธฐ

ํ’€์ด์‹œ๊ฐ„ : 15๋ถ„

์ด์ „์— ์‹œ๊ฐ„์„ Intํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ–ˆ๋˜ ๊ธฐ์–ต์„ ์‚ด๋ ค ๊ฐ„๋‹จํ•˜๊ฒŒ ํ’€์—ˆ๋‹ค. ๊ตฟ

profile

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป iOSun

@iosun

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!

profile on loading

Loading...