Skip to content

Commit

Permalink
Add 1732 find the highest altitude
Browse files Browse the repository at this point in the history
  • Loading branch information
escwxyz committed May 3, 2023
1 parent 390c48f commit 9175f90
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions typescript/src/1732-find-the-highest-altitude.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function largestAltitude(gain: number[]): number {
const arr = new Array(gain.length + 1).fill(0)

for (let i = 0; i < gain.length; i++) {
arr[i + 1] = arr[i] + gain[i]
}

return Math.max.apply(null, arr)
}

if (import.meta.vitest) {
const { test, expect } = import.meta.vitest
test('test one', () => {
expect(largestAltitude([-5, 1, 5, 0, -7])).toBe(1)
})
test('test two', () => {
expect(largestAltitude([-4, -3, -2, -1, 4, 3, 2])).toBe(0)
})
}

0 comments on commit 9175f90

Please sign in to comment.