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

Commit06fa524

Browse files
committed
update: 315 & 327
1 parentccab568 commit06fa524

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

‎README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
8787
|307|[Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/)|[JavaScript](./src/range-sum-query-mutable/res.js)|Medium|
8888
|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|
8989
|310|[Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees/)|[JavaScript](./src/minimum-height-trees/res.js)|Medium|
90+
|315|[Count of Smaller Numbers After Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/)|[JavaScript](./src/count-of-smaller-numbers-after-self/res.js)|Hard|
91+
|327|[Count of Range Sum](https://leetcode.com/problems/count-of-range-sum/)|[JavaScript](./src/count-of-range-sum/res.js)|Hard|
9092
|334|[Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence/)|[JavaScript](./src/increasing-triplet-subsequence/res.js)|Medium|
9193
|342|[Power of Four](https://leetcode.com/problems/power-of-four/)|[JavaScript](./src/power-of-four/res.js)|Easy|
9294
|344|[Reverse String](https://leetcode.com/problems/reverse-string/)|[JavaScript](./src/reverse-string/res.js)|Easy|

‎src/count-of-range-sum/res.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
*@param {number[]} nums
3+
*@param {number} lower
4+
*@param {number} upper
5+
*@return {number}
6+
*/
7+
varcountRangeSum=function(nums,lower,upper){
8+
constlen=nums.length;
9+
10+
11+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* 归并排序+索引数组
3+
*@param {number[]} nums
4+
*@return {number[]}
5+
*/
6+
varcountSmaller=function(nums){
7+
constlen=nums.length;
8+
if(!len)return[];
9+
if(len===1)return[0];
10+
11+
constindexList=nums.map((e,i)=>i);
12+
constres=nums.map(()=>0);
13+
14+
consthelper=(nums,left,right,indexList)=>{
15+
letmid=-1;
16+
if(left===right){
17+
return;
18+
}
19+
20+
mid=left+parseInt((right-left)/2);
21+
22+
helper(nums,left,mid,indexList)
23+
helper(nums,mid+1,right,indexList)
24+
25+
if(nums[indexList[mid]]<nums[indexList[mid+1]])
26+
return;
27+
28+
sort_and_count_smaller(nums,left,mid,right,indexList);
29+
}
30+
31+
constsort_and_count_smaller=(nums,left,mid,right,indexList)=>{
32+
consttemp=indexList.slice();
33+
34+
letl=left;
35+
letr=mid+1;
36+
for(leti=l;i<=right;i++){
37+
if(l>mid){// 左边遍历完
38+
indexList[i]=temp[r];
39+
r+=1;
40+
}elseif(r>right){// 右边遍历完
41+
indexList[i]=temp[l];
42+
l+=1;
43+
res[indexList[i]]+=(right-mid);
44+
}elseif(nums[temp[l]]<=nums[temp[r]]){//
45+
indexList[i]=temp[l];
46+
l+=1;
47+
res[indexList[i]]+=(r-mid-1);
48+
}elseif(nums[temp[l]]>nums[temp[r]]){
49+
indexList[i]=temp[r];
50+
r+=1;
51+
}
52+
}
53+
}
54+
55+
helper(nums,0,len-1,indexList);
56+
returnres;
57+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp