Home 2357. Make Array Zero by Subtracting Equal Amounts
Post
Cancel

2357. Make Array Zero by Subtracting Equal Amounts

2357. Make Array Zero by Subtracting Equal Amounts

Problem & Example

Questions before reading example

나의 풀이

time complexity : O(n^2)

space complexity : O(1)

다른 풀이 (SIMPLE, EASY-UNDERSTANDING)

1
2
3
4
5
6
7
8
9
10
class Solution {
  public int minimumOperations(int[] nums) {
    HashSet<Integer> set = new HashSet<>();
    for(int a : nums) {
      if(a > 0)
        set.add(a);
    }
    return set.size();
  }
}

Spent time

  • 5m

Review

  • 문제 그대로 brute force 하게 풀었다.
  • 하지만.. 문제를 깊이 이해하고 나면, Set 으로 한방에 풀 수 있다는 걸 알 수 있다. (물론 나도 discussion 을 보고 알았다)
  • 낮은 수부터 빼고, 중복숫자 빼고..
This post is licensed under CC BY 4.0 by the author.