Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions leetcode3/이진희/3833. Count Dominant Indices.java
Original file line number Diff line number Diff line change
@@ -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; i<nums.length-1; i++) {
double avg = (double)cnt[i]/(nums.length-1-i);
if(nums[i]>avg) ans++;
}

return ans;
}
}
52 changes: 52 additions & 0 deletions leetcode3/이진희/877. Stone Game.java
Original file line number Diff line number Diff line change
@@ -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<r) {
// // A
// if(piles[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;
}
}