Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 11, 2023
1 parent 153b7b2 commit 8518134
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"
)

func findSpecialInteger(arr []int) int {
for k, v := range arr {
if v == arr[k+(len(arr)>>2)] {
return v
}
}
return 0
}

func findSpecialInteger1(arr []int) int {
if len(arr) < 4 {
return arr[0]
}
count := 1
for i := 1; i < len(arr); i++ {
if arr[i] == arr[i-1] {
count++
if count > len(arr)/4 {
return arr[i]
}
} else {
count = 1
}

}
return -1
}

func main() {
arr := []int{1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12}
fmt.Println(findSpecialInteger1(arr))
}

0 comments on commit 8518134

Please sign in to comment.