From b6e1ba9725e49b3a8e49bc0ea189588e76284dee Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Mon, 28 Sep 2026 18:12:41 +0900 Subject: [PATCH] 169. Majority Element --- .../169. Majority Element.java" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/169. Majority Element.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/169. Majority Element.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/169. Majority Element.java" new file mode 100644 index 00000000..9ed78ab7 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/169. Majority Element.java" @@ -0,0 +1,30 @@ +/* + +1. 아이디어 : 공간복잡도를 O(1)로 유지하기 위해, 배열을 미리 정렬 후 완전탐색 + 9ms, 37.40%가 나왔으므로, 좋은 풀이는 아닌것같음.. + +2. 시간복잡도 : O(NlogN) + +3. 자료구조/알고리즘 : 완전탐색, 정렬 + + */ + +class Solution { + public int majorityElement(int[] nums) { + int idx = 0; + double base = (double)nums.length/2; + int cnt = 1; + + for(int i=1; i base) return second; + if( != second) { + idx = i; + } + else cnt++; + } + + return nums[idx]; + } +} \ No newline at end of file