Java Wrapper & Primitive comparison
- When both values are wrappers, use .equals() to avoid unexpected bevhaviors
- When both values are primitives, use ==, because .equals() is method that only exists in wrapper class
- When one value is wrapper, another value is primitive, use .equals() on wrapper, put the primitive value inside the bracket
Idea
- Window to include as many character as possible until we have all the character matches, then we start finding the anagram by shrinking the window (if current window is bigger than the given anagram)
- the shrinking stops when we find a matched anagram, and we proceed to expand the window, hopefully can find another anagram
Space & time analysis
Code
- 1st attempt (python)
- 2nd attempt (java)
- 3rd attempt (java) (13mins) ❤️
- 4th attempt (java)
O(np)
- 4.1th attempt (java)
O(n)
❤️❤️