Skip to content

Commit b723e86

Browse files
edit 523
1 parent 74feddd commit b723e86

File tree

1 file changed

+9
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+9
-0
lines changed

src/main/java/com/fishercoder/solutions/_523.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
*/
2828
public class _523 {
2929

30+
/**reference: https://discuss.leetcode.com/topic/80793/java-o-n-time-o-k-space/20
31+
*
32+
* "The reason we use modulus is:
33+
* (a+(n*x))%x is same as (a%x)
34+
* e.g. in case of the array [23,2,6,4,7] the running sum is [23,25,31,35,42]
35+
* and the remainders are [5,1,1,5,0].
36+
* We got reminder 5 at index 0 and at index 3.
37+
* That means, in between these two indexes we must have added a number which is multiple of the k.
38+
* Hope this clarifies your doubt :)"*/
3039
public boolean checkSubarraySumOnTimeO1Space(int[] nums, int k) {
3140
Map<Integer, Integer> map = new HashMap<>();
3241
map.put(0, -1);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy