Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. [-1234, 10, -1234, 1, -1234, 10, -1234, 1]
  2.  
  3. HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
  4. //String hashes are keys, # occurrences are values
  5.  
  6. for (int i = 0; i < str.length; i++) //two loops to loop through every subarray
  7. for (int j = i; j < str.length; j++) {
  8. int hash = 1;
  9. for (int k = i; k <= j; k++) //polynomial hash w/ a = 31
  10. hash = hash*31 + str[k];
  11.  
  12. System.out.println(!hm.containsKey(hash)); //debugging purposes
  13.  
  14. // faulty code?
  15.  
  16. if (!hm.containsKey(hash));
  17. hm.put(hash, 0);
  18. //
  19.  
  20. hm.put(hash, hm.get(hash)+1); //update occurrences
  21. }
  22.  
  23. false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement