Skip to content

Bugfix/s334 #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .circleci/config.yml

This file was deleted.

8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module github.com/TTWShell/algorithms

go 1.16
go 1.19

require github.com/stretchr/testify v1.7.0

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
32 changes: 16 additions & 16 deletions leetcode/array/increasingTriplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ Example 2:

package larray

func increasingTriplet(nums []int) bool {
left, right := -1, 0
for i := 1; i < len(nums); i++ {
if nums[i-1] >= nums[i] {
continue
}
import "math"

if left < 0 {
left, right = i-1, i
continue
}
func increasingTriplet(nums []int) bool {
if len(nums) < 3 {
return false
}

if nums[i-1] < nums[right] && nums[left] < nums[i-1] { // update right only
right = i - 1
min := nums[0]
minMid := math.MaxInt32
for i := 1; i < len(nums); i++ {
if nums[i] > minMid {
return true
}
if nums[i] < nums[right] { // need update all
left, right = i-1, i
if min > nums[i-1] {
min = nums[i-1]
}
if left >= 0 && nums[left] < nums[right] && nums[right] < nums[i] {
return true
if nums[i] > min {
if nums[i] < minMid {
minMid = nums[i]
}
}
}
return false
Expand Down
2 changes: 2 additions & 0 deletions leetcode/array/increasingTriplet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ func Test_increasingTriplet(t *testing.T) {
assert.False(increasingTriplet([]int{2, 1, 5, 0, 3}))
assert.True(increasingTriplet([]int{2, 1, 5, 0, 4, 6}))
assert.True(increasingTriplet([]int{1, 2, -10, -8, -7}))
assert.True(increasingTriplet([]int{0, 4, 1, -1, 2}))
assert.True(increasingTriplet([]int{20, 100, 10, 12, 5, 13}))
}
Loading