diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/3833. Count Dominant Indices.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/3833. Count Dominant Indices.java" new file mode 100644 index 00000000..61d338fd --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/3833. Count Dominant Indices.java" @@ -0,0 +1,27 @@ +/* + +1. 아이디어 : 각 인덱스 기준 i+1부터 배열끝까지 합을 누적합으로 계산 + 누적된 값의 평균이 배열 i보다 더 작다면 값 증가 + +2. 시간복잡도 : O(2N) + +3. 자료구조/알고리즘 : 누적합 + + */ + +class Solution { + public int dominantIndices(int[] nums) { + int[] cnt = new int[nums.length]; + int ans = 0; + + // len-2 ~ 0까지 + for(int i=nums.length-2; i>=0; i--) cnt[i]= cnt[i+1] + nums[i+1]; + + for(int i=0; iavg) ans++; + } + + return ans; + } +} \ No newline at end of file diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/877. Stone Game.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/877. Stone Game.java" new file mode 100644 index 00000000..469f081e --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/877. Stone Game.java" @@ -0,0 +1,52 @@ +/* + +1. 아이디어 : 짝수개의 돌, 돌의 총 개수는 홀수 + A->B로 번갈아가며 돌을 선택하고 이때 양끝 돌 중 하나를 선택 + + A가 이기면 true, B가 이기면 false + + 순서가 A부터 고정되고 가져가는 돌의 위치도 정해져 있어, 생각해보면 A는 항상 이길 수 있다. + + +2. 시간복잡도 : O(1) +자료구조/알고리즘 : 아이디어 + +*/ + +class Solution { + public boolean stoneGame(int[] piles) { + // A -> B + // 맨 앞과 맨 끝 중 돌 가져가기 + + // int l = 0; + // int r = piles.length-1; + // int a = 0; + // int b = 0; + + // while(l=piles[r]) { + // a+=piles[l]; + // l++; + // } + // else { + // a+=piles[r]; + // r--; + // } + + // // B + // if(piles[l]>piles[r]) { + // b+=piles[r]; + // r--; + // } + // else { + // b+=piles[l]; + // l++; + // } + // } + + // return a>b; + + return true; + } +} \ No newline at end of file