Skip to content

Commit

Permalink
feat: add typescript solution to lc problem: No.0162.Find Peak Element (
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaocchen authored Jun 21, 2021
1 parent 0105f30 commit 1b9d507
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions solution/0100-0199/0162.Find Peak Element/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ class Solution {
}
```

### **TypeScript**

```ts
function findPeakElement(nums: number[]): number {
let left = 0, right = nums.length - 1;
while (left < right) {
let mid: number = (left + right) >> 1;
if (nums[mid] <= nums[mid+1]) {
left = mid +1;
} else {
right = mid;
}
}
return left;
};
```

### **Go**

```go
Expand Down
17 changes: 17 additions & 0 deletions solution/0100-0199/0162.Find Peak Element/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ class Solution {
}
```

### **TypeScript**

```ts
function findPeakElement(nums: number[]): number {
let left = 0, right = nums.length - 1;
while (left < right) {
let mid: number = (left + right) >> 1;
if (nums[mid] <= nums[mid+1]) {
left = mid +1;
} else {
right = mid;
}
}
return left;
};
```

### **Go**

```go
Expand Down
12 changes: 12 additions & 0 deletions solution/0100-0199/0162.Find Peak Element/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function findPeakElement(nums: number[]): number {
let left = 0, right = nums.length - 1;
while (left < right) {
let mid: number = (left + right) >> 1;
if (nums[mid] <= nums[mid+1]) {
left = mid +1;
} else {
right = mid;
}
}
return left;
};

0 comments on commit 1b9d507

Please sign in to comment.