и посмотреть медиа
Swift| LeetCode - tasks
и посмотреть медиа
LeetCode tasksSwiftJobs and vacancies foriOS- developers.
LeetCode tasksSwiftJobs and vacancies foriOS- developers.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
Resource forSwiftDevelopers with LeetCode tasks. Practice algorithms, optimization andiOS- Specifics:arrays.strings.treesonSwift. Preparation for interviews.📱Security questions include typical tasks from Apple and other companies. Code parsing, patterns andbest practicesfor mobile development. From basic to advanced level.⚡VacanciesSwift/iOS devsThey are updated regularly. It is a comprehensive tool for growth: from theory to practice and employment to mobile development.
Задача: 561. Array Partition Сложность: easy Дан массив целых чисел nums из 2n элементов. Разделите эти числа на n пар (a1, b1), (a2, b2), ..., (an, bn) так, чтобы сумма min(ai, bi) для всех i была максимальной. Верните максимальную сумму. Пример: Input: nums = [1,4,3,2] Output: 4 Explanation: All possible pairings (ignoring the ordering of elements) are: 1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3 2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3 3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4 So the maximum possible sum is 4. 👨💻 Алгоритм: 1⃣Отсортируйте массив nums в неубывающем порядке. 2⃣Итерируйте через массив, выбирая каждый второй элемент (начиная с первого). 3⃣Суммируйте выбранные элементы и верните эту сумму. 😎 Решение: class Solution { func arrayPairSum(_ nums: [Int]) -> Int { let sortedNums = nums.sorted() var sum = 0 for i in stride(from: 0, to: sortedNums.count, by: 2) { sum += sortedNums[i] } return sum } } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!