и посмотреть медиа
Java | LeetCode
и посмотреть медиа
LeetCode tasks and solutions in Java.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
LeetCode task solutions in Java with emphasis on clean code and optimization. Topics: arrays, trees, graphs, dynamic programming. Ideal for technical preparation.
Задача: 1207. Unique Number of Occurrences Сложность: easy Дан массив целых чисел arr. Верните true, если количество вхождений каждого значения в массиве уникально, или false в противном случае. Пример: Input: arr = [1,2,2,1,1,3] Output: true Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences. 👨💻 Алгоритм: 1⃣Сохраните частоты элементов массива arr в хэш-таблице freq. 2⃣Итерируйтесь по хэш-таблице freq и вставьте частоты всех уникальных элементов массива arr в хэш-набор freqSet. 3⃣Верните true, если размер хэш-набора freqSet равен размеру хэш-таблицы freq, иначе верните false. 😎 Решение: class Solution { public boolean uniqueOccurrences(int[] arr) { Map freq = new HashMap(); for (int num : arr) { freq.put(num, freq.getOrDefault(num, 0) + 1); } Set freqSet = new HashSet(freq.values()); return freq.size() == freqSet.size(); } } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!