и посмотреть медиа
Kotlin | LeetCode
и посмотреть медиа
LeetCode problems and solutions in Kotlin.
LeetCode problems and solutions in Kotlin.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
LeetCode problem solutions in Kotlin. Optimized code for mobile developers and algorithm specialists.
Задача: 1512. Number of Good Pairs Сложность: easy Дан массив целых чисел nums, верните количество хороших пар. Пара (i, j) называется хорошей, если nums[i] == nums[j] и i < j. Пример: Input: nums = [1,2,3,1,1,3] Output: 4 Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed. 👨💻 Алгоритм: 1⃣Инициализируйте переменную ans значением 0. 2⃣Итерируйте i от 0 до nums.length: Итерируйте j от i + 1 до nums.length: Если nums[i] == nums[j], увеличьте ans на 1. 3⃣Верните ans. 😎 Решение: class Solution { fun numIdenticalPairs(nums: IntArray): Int { var ans = 0 for (i in nums.indices) { for (j in i + 1 until nums.size) { if (nums[i] == nums[j]) { ans++ } } } return ans } } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!