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

Commit dcf8f96

Browse files
author
Openset
committed
Update: Third Maximum Number
1 parent 11fbc47 commit dcf8f96

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

‎problems/third-maximum-number/third_maximum_number.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package third_maximum_number
22

33
func thirdMax(nums []int) int {
4-
max1, max2, max3 := -1, -1, -1
4+
max1, max2, max3 := 0, -1, -1
55
for i, v := range nums {
6-
if max1==-1||v > nums[max1] {
6+
if v > nums[max1] {
77
max1, max2, max3 = i, max1, max2
88
} else if (max2 == -1 || v > nums[max2]) && v != nums[max1] {
99
max2, max3 = i, max2

‎problems/third-maximum-number/third_maximum_number_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ type caseType struct {
99

1010
func TestThirdMax(t *testing.T) {
1111
tests := [...]caseType{
12+
{
13+
input: []int{1, 2, 2, 5, 3, 5},
14+
expected: 2,
15+
},
16+
{
17+
input: []int{1, 2, 2},
18+
expected: 2,
19+
},
20+
{
21+
input: []int{1, 1, 2},
22+
expected: 2,
23+
},
1224
{
1325
input: []int{3, 2, 1},
1426
expected: 1,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /