и посмотреть медиа
Java LeetCode
и посмотреть медиа
Tareas y soluciones de LeetCode en Java.
bot de IA para clonar texto a voz y voz en Telegram. Cree audio utilizando la red neuronal de forma rápida y fácil.
Soluciones de tareas de LeetCode en Java con énfasis en código limpio y optimización. Temas: arrays, árboles, gráficos, programación dinámica. Ideal para la preparación técnica.
Задача: 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(); } } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаSolo los usuarios registrados pueden compartir su opinión.
¡Sé el primero en compartir tu experiencia con este recurso!