@@ -372,53 +372,6 @@ func jobScheduling(startTime []int, endTime []int, profit []int) int {
372
372
}
373
373
```
374
374
375
- #### Swift
376
-
377
- ``` swift
378
- class Solution {
379
-
380
- func binarySearch <T :Comparable >(inputArr : [T], searchItem : T) -> Int ? {
381
- var lowerIndex = 0
382
- var upperIndex = inputArr.count - 1
383
-
384
- while (lowerIndex < upperIndex) {
385
- let currentIndex = (lowerIndex + upperIndex)/ 2
386
- if (inputArr[currentIndex] <= searchItem) {
387
- lowerIndex = currentIndex + 1
388
- } else {
389
- upperIndex = currentIndex
390
- }}
391
-
392
- if (inputArr[upperIndex] <= searchItem) {return upperIndex + 1 }
393
- return lowerIndex
394
-
395
- }
396
-
397
-
398
- func jobScheduling (_ startTime : [Int ], _ endTime : [Int ], _ profit : [Int ]) -> Int {
399
- let zipList = zip (zip (startTime, endTime), profit)
400
- var table: [(startTime:Int , endTime:Int , profit:Int , cumsum: Int )] = []
401
-
402
- for ((x,y),z) in zipList {
403
- table.append ((x,y,z, 0 ))
404
- }
405
- table.sort (by : {$0 .endTime < $1 .endTime })
406
- let sortedEndTime = endTime.sorted ()
407
-
408
- var profits: [Int ] = [0 ]
409
- for iJob in table {
410
- let index: Int ! = binarySearch (inputArr : sortedEndTime, searchItem : iJob.startTime )
411
- if profits.last ! < profits[index] + iJob.profit {
412
- profits.append (profits[index] + iJob.profit )
413
- } else {
414
- profits.append (profits.last ! )
415
- }
416
- }
417
- return (profits.last ! )
418
- }
419
- }
420
- ```
421
-
422
375
#### TypeScript
423
376
424
377
``` ts
@@ -451,6 +404,54 @@ function jobScheduling(startTime: number[], endTime: number[], profit: number[])
451
404
}
452
405
```
453
406
407
+ #### Swift
408
+
409
+ ``` swift
410
+ class Solution {
411
+
412
+ func binarySearch <T : Comparable >(inputArr : [T], searchItem : T) -> Int ? {
413
+ var lowerIndex = 0
414
+ var upperIndex = inputArr.count - 1
415
+
416
+ while lowerIndex < upperIndex {
417
+ let currentIndex = (lowerIndex + upperIndex) / 2
418
+ if inputArr[currentIndex] <= searchItem {
419
+ lowerIndex = currentIndex + 1
420
+ } else {
421
+ upperIndex = currentIndex
422
+ }
423
+ }
424
+
425
+ if inputArr[upperIndex] <= searchItem {
426
+ return upperIndex + 1
427
+ }
428
+ return lowerIndex
429
+ }
430
+
431
+ func jobScheduling (_ startTime : [Int ], _ endTime : [Int ], _ profit : [Int ]) -> Int {
432
+ let zipList = zip (zip (startTime, endTime), profit)
433
+ var table: [(startTime: Int , endTime: Int , profit: Int , cumsum: Int )] = []
434
+
435
+ for ((x, y), z) in zipList {
436
+ table.append ((x, y, z, 0 ))
437
+ }
438
+ table.sort (by : { $0 .endTime < $1 .endTime })
439
+ let sortedEndTime = endTime.sorted ()
440
+
441
+ var profits: [Int ] = [0 ]
442
+ for iJob in table {
443
+ let index: Int ! = binarySearch (inputArr : sortedEndTime, searchItem : iJob.startTime )
444
+ if profits.last ! < profits[index] + iJob.profit {
445
+ profits.append (profits[index] + iJob.profit )
446
+ } else {
447
+ profits.append (profits.last ! )
448
+ }
449
+ }
450
+ return profits.last !
451
+ }
452
+ }
453
+ ```
454
+
454
455
<!-- tabs: end -->
455
456
456
457
<!-- solution: end -->
0 commit comments