---
# System prepended metadata

title: 2453. Destroy Sequential Targets
tags: [Leetcode, Medium, Math]

---

# 2453. Destroy Sequential Targets
###### tags: `Leetcode` `Medium` `Math`
Link: https://leetcode.com/problems/destroy-sequential-targets/description/
## 思路
把每个数字对space取余数 然后存进map里
找出所有余数里面 cnt最大的那一个 答案就是这个group里面最小的数
## Code
```java=
class Solution {
    public int destroyTargets(int[] nums, int space) {
        Map<Integer, Integer> cnt = new HashMap<>();
        for(int num:nums){
            cnt.put(num%space, cnt.getOrDefault(num%space, 0)+1);
        }
        int maxc = Collections.max(cnt.values());
        int ans = Integer.MAX_VALUE;
        for(int num:nums){
            if(cnt.get(num%space)==maxc) ans = Math.min(ans, num);
        }
        return ans;
    }
}
```