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

Commitad9fb1e

Browse files
committed
add new files
1 parent57590df commitad9fb1e

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

‎456. 132 Pattern.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"math"
5+
)
6+
7+
funcfind132pattern(nums []int)bool {
8+
m:=math.MaxInt32
9+
forj:=0;j<len(nums);j++ {
10+
m=min(nums[j],m)
11+
ifm==nums[j] {
12+
continue
13+
}
14+
fork:=len(nums)-1;k>j;k-- {
15+
ifm<nums[k]&&nums[k]<nums[j] {
16+
returntrue
17+
}
18+
}
19+
}
20+
returnfalse
21+
}
22+
23+
funcmin(x,yint)int {
24+
ifx>y {
25+
returny
26+
}
27+
returnx
28+
}
29+
30+
//fastest AC code
31+
//use stack
32+
funcfind132pattern1(nums []int)bool {
33+
ell:=len(nums)
34+
ifell<3 {
35+
returnfalse
36+
}
37+
38+
stack:=make([]int,1,ell)
39+
stack[0]=nums[ell-1]
40+
41+
fori,s3:=ell-2,math.MinInt32;i>=0;i-- {
42+
ifnums[i]<s3 {
43+
returntrue
44+
}
45+
46+
forj:=len(stack)-1;j>=0&&stack[j]<nums[i];j-- {
47+
s3,stack=stack[j],stack[:j]
48+
}
49+
stack=append(stack,nums[i])
50+
}
51+
52+
returnfalse
53+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import"sort"
4+
5+
funcminMoves2(nums []int)int {
6+
sort.Ints(nums)
7+
i,j:=0,len(nums)-1
8+
count:=0
9+
fori<j {
10+
count+=nums[j]-nums[i]
11+
i++
12+
j--
13+
}
14+
returncount
15+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp