A Solution Set Restricted to Java Language
The practice on LeetCode was started late November 2019, writing this post can remind me how I thought about the question at the time.
Problem 2: Add Two Numbers (Medium, List Manipulation)
we can assign an extra node to form the result list.
Monitor the current two digits to calculate the carry and then do the normal addition work.
Remember to check the null node when the length of two adders are different
Problem 3: Longest Substring Without Repeating Characters (Medium, Sliding Window)
My thoughts:
- Using greedy to store the length of longest non-repeating substring
- When encounter a duplicated character, recording the length between two duplicted character
- Then comparing it with the current length plus one to deal with the special case “abba”
1 | currentLength = (currentLength + 1) < lengthBetween ? currentLength + 1 : lengthBetween; //deal with "abba" |
Provided Solution
Problem 4: Median of Two Sorted Arrays (Hard, Optimized Half Search)
- To be continued