August 22, 2016
Continue to review solutions on Leetcode 125.
1. study code:
https://github.com/jianminchen/leetcode-1/blob/master/algorithms/validPalindrome/validPalindrome.cpp
extract one more function - removeNoise - practice #10
C# practice
Great idea to extract one more function, SRP - single responsibility principle
- make the code much more easy to follow, test, static analysis
Two tasks - put into one function - first ask if the function can be broken into two, what is the checkpoints?
Both are with time complexity O(N), N is the string length;
Two tasks can be separated easily, task 1 can be done first.
1. remove noise
2. compare chars
Easily, combine the above 1 and 2 cases, there are 4 cases in the function to handle.
2. use continue keyword - practice #11
study code:
C# practice:
No comments:
Post a Comment