forked from CBNU-Nnet/2022-algorithm-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3주차] : 홍범순 - 5883 아이폰 9S Silver4 (CBNU-Nnet#60)
- Loading branch information
beomsun0829
committed
Jul 13, 2022
1 parent
85ff4b7
commit 1f81911
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |