Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit72570cc

Browse files
committed
update: 295
1 parenta4bfe01 commit72570cc

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
8888
|275|[H-Index II](https://leetcode.com/problems/h-index-ii/)|[JavaScript](./src/h-index-ii/res.js)|Medium|
8989
|287|[Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/)|[JavaScript](./src/find-the-duplicate-number/res.js)|Medium|
9090
|289|[Game of Life](https://leetcode.com/problems/game-of-life/)|[JavaScript](./src/game-of-life/res.js)|Medium|
91+
|295|[Find Median from Data Stream](https://leetcode.com/problems/find-median-from-data-stream/)|[JavaScript](./src/find-median-from-data-stream/res.js)|Hard|
9192
|299|[Bulls and Cows](https://leetcode.com/problems/bulls-and-cows/)|[JavaScript](./src/bulls-and-cows/res.js)|Medium|
9293
|307|[Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/)|[JavaScript](./src/range-sum-query-mutable/res.js)|Medium|
9394
|309|[Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/)|[JavaScript](./src/best-time-to-buy-and-sell-stock-with-cooldown/res.js)|Medium|
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* 二分法排序 + 查找
3+
* initialize your data structure here.
4+
*/
5+
varMedianFinder=function(){
6+
this.nums=[];
7+
};
8+
9+
/**
10+
*@param {number} num
11+
*@return {void}
12+
*/
13+
MedianFinder.prototype.addNum=function(num){
14+
//
15+
constbs=(n)=>{
16+
letstart=0;
17+
letend=this.nums.length;
18+
19+
while(start<end){
20+
letmid=(start+end)>>1;
21+
if(n>this.nums[mid]){
22+
start=mid+1;
23+
}else{
24+
end=mid;
25+
}
26+
}
27+
this.nums.splice(start,0,n);
28+
}
29+
30+
if(this.nums.length){
31+
bs(num);
32+
}else{
33+
this.nums.push(num);
34+
}
35+
};
36+
37+
/**
38+
*@return {number}
39+
*/
40+
MedianFinder.prototype.findMedian=function(){
41+
constlen=this.nums.length;
42+
returnlen ?len%2 ?this.nums[Math.floor(len/2)] :(this.nums[len/2]+this.nums[len/2-1])/2 :null;
43+
};
44+
45+
/**
46+
* Your MedianFinder object will be instantiated and called as such:
47+
* var obj = new MedianFinder()
48+
* obj.addNum(num)
49+
* var param_2 = obj.findMedian()
50+
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp