и посмотреть медиа
Golang | LeetCode
и посмотреть медиа
LeetCode tasks in Golang. Solutions with code and explanations.
LeetCode tasks in Golang. Solutions with code and explanations.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
Channel with solutions to popular LeetCode tasks in Go. Focus on optimized algorithms, efficient memory usage, and idiomatic code. Helps prepare for technical interviews in companies that use Golang.
Задача: 1480. Running Sum of 1d Array Сложность: easy Дан массив nums. Мы определяем текущую сумму массива как runningSum[i] = сумма(nums[0]…nums[i]). Верните массив текущих сумм для nums. Пример: Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]. 👨💻 Алгоритм: 1⃣Инициализация: Определите массив result. Инициализируйте первый элемент массива result первым элементом входного массива nums. 2⃣Вычисление текущих сумм: На индексе i добавьте сумму элемента nums[i] и предыдущей текущей суммы result[i - 1] в массив result. 3⃣Повторение для всех индексов: Повторите шаг 2 для всех индексов от 1 до n-1. 😎 Решение: func runningSum(nums []int) []int { result := make([]int, len(nums)) result[0] = nums[0] for i := 1; i < len(nums); i++ { result[i] = result[i-1] + nums[i] } return result } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!