Skip to content

Commit cbaa86e

Browse files
authored
Update README.md
1 parent 1ac5755 commit cbaa86e

File tree

1 file changed

+48
-47
lines changed
  • solution/1200-1299/1235.Maximum Profit in Job Scheduling

1 file changed

+48
-47
lines changed

solution/1200-1299/1235.Maximum Profit in Job Scheduling/README.md

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -380,53 +380,6 @@ func jobScheduling(startTime []int, endTime []int, profit []int) int {
380380
}
381381
```
382382

383-
#### Swift
384-
385-
```swift
386-
class Solution {
387-
388-
func binarySearch<T:Comparable>(inputArr: [T], searchItem: T) -> Int? {
389-
var lowerIndex = 0
390-
var upperIndex = inputArr.count - 1
391-
392-
while (lowerIndex < upperIndex) {
393-
let currentIndex = (lowerIndex + upperIndex)/2
394-
if (inputArr[currentIndex] <= searchItem) {
395-
lowerIndex = currentIndex + 1
396-
} else {
397-
upperIndex = currentIndex
398-
}}
399-
400-
if (inputArr[upperIndex] <= searchItem) {return upperIndex + 1}
401-
return lowerIndex
402-
403-
}
404-
405-
406-
func jobScheduling(_ startTime: [Int], _ endTime: [Int], _ profit: [Int]) -> Int {
407-
let zipList = zip(zip(startTime, endTime), profit)
408-
var table: [(startTime:Int, endTime:Int, profit:Int, cumsum: Int)] = []
409-
410-
for ((x,y),z) in zipList {
411-
table.append((x,y,z, 0))
412-
}
413-
table.sort(by: {$0.endTime < $1.endTime})
414-
let sortedEndTime = endTime.sorted()
415-
416-
var profits: [Int] = [0]
417-
for iJob in table {
418-
let index: Int! = binarySearch(inputArr: sortedEndTime, searchItem: iJob.startTime)
419-
if profits.last! < profits[index] + iJob.profit {
420-
profits.append(profits[index] + iJob.profit)
421-
} else {
422-
profits.append(profits.last!)
423-
}
424-
}
425-
return (profits.last!)
426-
}
427-
}
428-
```
429-
430383
#### TypeScript
431384

432385
```ts
@@ -459,6 +412,54 @@ function jobScheduling(startTime: number[], endTime: number[], profit: number[])
459412
}
460413
```
461414

415+
#### Swift
416+
417+
```swift
418+
class Solution {
419+
420+
func binarySearch<T: Comparable>(inputArr: [T], searchItem: T) -> Int? {
421+
var lowerIndex = 0
422+
var upperIndex = inputArr.count - 1
423+
424+
while lowerIndex < upperIndex {
425+
let currentIndex = (lowerIndex + upperIndex) / 2
426+
if inputArr[currentIndex] <= searchItem {
427+
lowerIndex = currentIndex + 1
428+
} else {
429+
upperIndex = currentIndex
430+
}
431+
}
432+
433+
if inputArr[upperIndex] <= searchItem {
434+
return upperIndex + 1
435+
}
436+
return lowerIndex
437+
}
438+
439+
func jobScheduling(_ startTime: [Int], _ endTime: [Int], _ profit: [Int]) -> Int {
440+
let zipList = zip(zip(startTime, endTime), profit)
441+
var table: [(startTime: Int, endTime: Int, profit: Int, cumsum: Int)] = []
442+
443+
for ((x, y), z) in zipList {
444+
table.append((x, y, z, 0))
445+
}
446+
table.sort(by: { $0.endTime < $1.endTime })
447+
let sortedEndTime = endTime.sorted()
448+
449+
var profits: [Int] = [0]
450+
for iJob in table {
451+
let index: Int! = binarySearch(inputArr: sortedEndTime, searchItem: iJob.startTime)
452+
if profits.last! < profits[index] + iJob.profit {
453+
profits.append(profits[index] + iJob.profit)
454+
} else {
455+
profits.append(profits.last!)
456+
}
457+
}
458+
return profits.last!
459+
}
460+
}
461+
```
462+
462463
<!-- tabs:end -->
463464

464465
<!-- solution:end -->

0 commit comments

Comments
 (0)