Tag: leetcode
933 Number of Recent Calls
link: Number of Recent Calls Thought Question ask for numbers of calls in 3000. So sliding windows is my choice here – it will move and drop calls earlier than 3000 – which I don’t care, and keep tracing incoming calls. Code Runtime Time: O(n)Space: O(n)
Read More → 933 Number of Recent Calls935 Knight Dialer
link Knight Dialer Thought Since it ask how many distinct numbers could be generated, DP jumps to my mind immediately. Firstly, the relation is, if knight stop at number 6, it has to come from 1, 7, or 0. So I keep a DP array, DP[j][i] stands for how many unique numbers it could generate […]
Read More → 935 Knight Dialer934 Shortest Bridge
link: Shortest Bridge Thought Since the question ask for shortest, so BFS probabely the best algorithms to solve it. But notice, I will use 2 bfs funciton, one to find the edge of first island, the other one is to reach another island based on first edge. BFS1: input: start positionstop condition: queue emptygenerate & […]
Read More → 934 Shortest Bridge931 Minimum Falling Path Sum
Link 931.Minimum Falling Path Sum Thought DFS When first seeing this question, DFS prompt into my mind directly. Take Any node from first level as start, and search down stream. Until reach node in last level. For any path, it will have a value. Find the minimum value and it will be the answer However, for […]
Read More → 931 Minimum Falling Path Sum929. Unique Email Addresses
Link: Unique Email Addresses Thought Brutal Force SolutionThis question is pretty simple (and it actually is an esay one). A naive approache is, split the name and domain. For the name, remove every thing after first ‘+’, and then replace all ‘.’ as empty. For the domain, just keep it is. Then, use a set […]
Read More → 929. Unique Email Addresses