Skip to content

Commit

Permalink
[3주차] : 홍범순 - 5883 아이폰 9S Silver4 (CBNU-Nnet#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
beomsun0829 committed Jul 13, 2022
1 parent 85ff4b7 commit 1f81911
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions 홍범순/5883 - 아이폰 9S/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main

import (
"fmt"
)

var N int

func main() {
fmt.Scan(&N)

var arr []int = make([]int, N)

for i := 0; i < N; i++ {
fmt.Scan(&arr[i])
}
var B [1000010]bool
ans := 1

for i := 0; i < 1000010; i++ {
B[i] = false
}

for i := 0; i < N; i++ {
if B[arr[i]] == false {
mx := 1
cnt := 1

newArr := popNumberFromArray(arr, arr[i])

for j := 1; j < len(newArr); j++ {
if newArr[j] == newArr[j-1] {
cnt += 1
} else {
mx = max(cnt, mx)
cnt = 1
}
}
mx = max(cnt, mx)

B[arr[i]] = true
ans = max(ans, mx)
}
}

fmt.Println(ans)
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

func popNumberFromArray(arr []int, num int) []int {
var newArr []int
for i := 0; i < len(arr); i++ {
if arr[i] != num {
newArr = append(newArr, arr[i])
}
}

return newArr
}

0 comments on commit 1f81911

Please sign in to comment.