Week 2
Monday
Problem
Solution
My Solution
I basically use two for loops to decide whether the nums[] is monotonic increase or decrease. This seems a bit tedious.
Good Solution
It uses two indicators isInc and isDec to mark whether the array is either increasing or decreasing, thus only need one loop can solve
Tuesday
Problem
Solution
The key of this solution is to notice the rule of transition for dx and dy, which is everything you are about to go out of boundary or visit the visited cell, you transit dx=-dy, dy=dx. (y is the column positive and x is the row position)
Wednesday*
Problem
Solution
Today's problem is interesting. Bascially, we need to learn that whenever we are dealing with robot-centered problem, use a fixed 2-D map to record the available four steps!
And for this problem, we just need to find the final vector, if it is not facing north, or the robot stays at the origin, then the robot will be in a circle.
Thursday
Problem
Solution
Slow Solution
Basically, it sorts the array first. And compare the sorted array with the unsorted one, the first unmatch element's position is denoted by start, and the last unmatch element's position is denoted by end, then the length will be end - start + 1.
Friday
Problem
Solution
This is an easy problem. No discussion.
Last updated