LeetCode 560 | Subarray Sum Equals K | Solution Explained (Java + Whiteboard)

preview_player
Показать описание
The description reads:
"Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.

Example 1:

Input:nums = [1,1,1], k = 2
Output: 2


Constraints:

The length of the array is in range [1, 20,000].
The range of numbers in the array is [-1000, 1000] and the range of the integer k is [-1e7, 1e7].
Accepted
353,953
Submissions
807,646"

Running Time: O(N)
Space Complexity: O(N)

Always be pluggin:
Рекомендации по теме
Комментарии
Автор

So, does anyone understands this problem at all, or are we all just copy pasting the same exact solution without actually understanding what's going on? I can tell by the way Xavier explained it, that he doesn't get it at all. He just memorized the code. And the explanation was done on a [1, 1, 1] array. Imagine if it was [7, 3, 2, 1, 8, 5, 4, 9], int k = 6. He would go into an infinite loop of confusion.

ladro_magro