From 1f81911555815255ca436c17513b7d5faa8cfd27 Mon Sep 17 00:00:00 2001 From: beomsun0829 Date: Wed, 13 Jul 2022 18:45:36 +0900 Subject: [PATCH] =?UTF-8?q?[3=EC=A3=BC=EC=B0=A8]=20:=20=ED=99=8D=EB=B2=94?= =?UTF-8?q?=EC=88=9C=20-=205883=20=EC=95=84=EC=9D=B4=ED=8F=B0=209S=20Silve?= =?UTF-8?q?r4=20(#60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main.go" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "\355\231\215\353\262\224\354\210\234/5883 - \354\225\204\354\235\264\355\217\260 9S/main.go" diff --git "a/\355\231\215\353\262\224\354\210\234/5883 - \354\225\204\354\235\264\355\217\260 9S/main.go" "b/\355\231\215\353\262\224\354\210\234/5883 - \354\225\204\354\235\264\355\217\260 9S/main.go" new file mode 100644 index 0000000..c952804 --- /dev/null +++ "b/\355\231\215\353\262\224\354\210\234/5883 - \354\225\204\354\235\264\355\217\260 9S/main.go" @@ -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 +}