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

Commit66ff35f

Browse files
authored
Merge pull requestneetcode-gh#1925 from AkifhanIlgaz/0456
Create: 0456-132-pattern.rs / .ts / .js
2 parents165ef04 +9787603 commit66ff35f

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

‎javascript/0456-132-pattern.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
*@param {number[]} nums
3+
*@return {boolean}
4+
*/
5+
varfind132pattern=function(nums){
6+
letstack=[];// [num, minLeft]
7+
letcurMin=nums[0];
8+
9+
for(nofnums.slice(1)){
10+
while(stack.length>0&&n>=stack.at(-1)[0]){
11+
stack.pop();
12+
}
13+
if(stack.length>0&&n>stack.at(-1)[1]){
14+
returntrue;
15+
}
16+
17+
stack.push([n,curMin]);
18+
curMin=Math.min(curMin,n);
19+
}
20+
21+
returnfalse;
22+
};

‎rust/0456-132-pattern.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
implSolution{
2+
pubfnfind132pattern(nums:Vec<i32>) ->bool{
3+
letmut stack:Vec<(i32,i32)> =vec![];// (num, min_left)
4+
letmut current_min = nums[0];
5+
6+
for nin nums.iter().skip(1){
7+
while !stack.is_empty() &&*n >= stack.last().unwrap().0{
8+
stack.pop();
9+
}
10+
if !stack.is_empty() &&*n > stack.last().unwrap().1{
11+
returntrue;
12+
}
13+
14+
stack.push((*n, current_min));
15+
current_min = current_min.min(*n);
16+
}
17+
18+
false
19+
}
20+
}

‎typescript/0456-132-pattern.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
functionfind132pattern(nums:number[]):boolean{
2+
letstack:{num:number;minLeft:number}[]=[];// [num, minLeft]
3+
letcurMin=nums[0];
4+
5+
for(letnofnums.slice(1)){
6+
while(stack.length>0&&n>=stack[stack.length-1].num){
7+
stack.pop();
8+
}
9+
if(stack.length>0&&n>stack[stack.length-1].minLeft){
10+
returntrue;
11+
}
12+
13+
stack.push({num:n,minLeft:curMin});
14+
curMin=Math.min(curMin,n);
15+
}
16+
17+
returnfalse;
18+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp