Created
October 16, 2020 12:36
-
-
Save Mr00Anderson/9681f7e1d63442f90c3f174e2a7470f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.virtual_hex.gdx.engine.maps; | |
import com.badlogic.gdx.math.Vector2; | |
import com.badlogic.gdx.utils.Array; | |
import com.badlogic.gdx.utils.IntIntMap; | |
public class SubArraySum { | |
public static void main(String[] args) { | |
IntIntMap indexToSumMapping = new IntIntMap(); | |
Array<Vector2> listOfMatching = new Array<>(); | |
int arr[] = { 3, 4, -7, 3, 1, 3, 1, -4, -2, -2 }; | |
int sum = 0; | |
for(int i = 0;i < arr.length;i++) { | |
int number = arr[i]; | |
sum += number; | |
System.out.println(sum); | |
if (indexToSumMapping.containsKey(sum)) { | |
listOfMatching.add(new Vector2(indexToSumMapping.get(sum, 0), i)); | |
} | |
indexToSumMapping.put(sum, i); | |
} | |
System.out.println(indexToSumMapping); | |
System.out.println(listOfMatching); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment