Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [-1234, 10, -1234, 1, -1234, 10, -1234, 1]
- HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
- //String hashes are keys, # occurrences are values
- for (int i = 0; i < str.length; i++) //two loops to loop through every subarray
- for (int j = i; j < str.length; j++) {
- int hash = 1;
- for (int k = i; k <= j; k++) //polynomial hash w/ a = 31
- hash = hash*31 + str[k];
- System.out.println(!hm.containsKey(hash)); //debugging purposes
- // faulty code?
- if (!hm.containsKey(hash));
- hm.put(hash, 0);
- //
- hm.put(hash, hm.get(hash)+1); //update occurrences
- }
- false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement