Repository navigation
Expand file tree
/
Copy path기능개발.swift
More file actions
64 lines (58 loc) · 1.58 KB
/
Copy path기능개발.swift
File metadata and controls
64 lines (58 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// 기능개발.swift
// Programmers1
//
// Created by hwangJi on 2023/04/01.
//
import Foundation
func solution(progresses:[Int], speeds:[Int]) -> [Int] {
var res: [Int] = []
var count = 0
var day = 0
for (idx, progress) in progresses.enumerated() {
let remain = ((100 - progress) / speeds[idx]) + (((100 - progress) % speeds[idx]) == 0 ? 0 : 1)
if day == 0 {
day = remain
}
if day < remain {
day = remain
res.append(count)
count = 1
} else {
count += 1
}
}
return count > 0 ? res + [count] : res
}
//func solution(_ progresses:[Int], _ speeds:[Int]) -> [Int] {
// var remains: [Int] = []
//
// for (idx, progress) in progresses.enumerated() {
// let remain = ((100 - progress) / speeds[idx]) + (((100 - progress) % speeds[idx]) == 0 ? 0 : 1)
// remains.append(remain)
// }
//
// remains = remains.reversed()
//
// var distributionCount = 0
// var distributionDay = 0
// var res: [Int] = []
//
// if let rem = remains.popLast() {
// distributionDay = rem
// distributionCount = 1
// }
//
// while !remains.isEmpty {
// if distributionDay >= remains.last! {
// remains.popLast()
// distributionCount += 1
// } else {
// distributionDay = remains.popLast() ?? 0
// res.append(distributionCount)
// distributionCount = 1
// }
// }
//
// return distributionCount == 0 ? res : res + [distributionCount]
//}