1. how to sort list of objects, based on attribute of the objects
2. compare Unicode difference between B and A ord('B') - ord('A')
3. carry, curr = divmod(val1 + val2 + carry, 10)
Wednesday, August 16, 2017
What happens when you press Google.com in your browser?
1. Parse
The line gets parsed and the protocol, server, port, query gets retrieved
2. Resolve to IP Address
Browser connects to server at the default/specified port
2.1. If it is in local DNS cache, fetch it
2.2. Else, recursively check IPS's DNS servers
3. Send Request
Browser sends a GET request followed a crlf sequence then by the headers all followed by respective crlf-s
3.1 If this server has already cached cookies, the browser sends them as cookie headers
3.2 If the browser supports compression it tells the server what compression is using (via headers) as well as what compression it could accept in return
3.3 Sends a content-length header set to value "0"
3.4. Sends a header instructing the server how to denote the end of its transmission stream. Connection: Close would be the most common
3.5 Sends a crlf sequence to mark the end of the headers (after eventual other headers are sent)
4. Handle Response
4.1. Parses the response code / status
4.2. If this response starts with 2 it caches cookies, decompresses (if header is mentioning compression) parses and displays the html content of message body (executing eventual scripts hooked to different DOM elements/events)
4.3 If the response code starts with 3 redirects t the server mentioned in the response (goto 11)
4.4 If the response code starts with 4 or 5 parses the response and displays it to the user
[Leetcode]Balanced Binary Tree
0. Line 8, 10, Use root as method signature, cuz if you use left and right, it would be tricky to implement line 11,12
1. Line 22, handle normal case by making sure left and right values are inbound and then return the bigger height
2. Line 23, cuz the current root also has height of 1, so should return 1
Tree Related knowledge
1. What is a balanced binary tree?
Absolution difference between left sub-tree and right sub-tree is bigger than 1
Absolution difference between left sub-tree and right sub-tree is bigger than 1
A good video can be found here https://www.youtube.com/watch?v=TWDigbwxuB4
2. What is BFS:
scan level by level
3. What is DFS:
go down first then go back.
we have preorder, inorder and postorder. pre/in/post describe where is the root node.
1
2 3
4 5 6 7
preorder: 1, 2, 4, 5, 3, 6, 7
inorder: 4, 2, 5, 1, 6, 3, 7
postorder: 4, 5, 2, 6, 7, 3, 1
[Leetcode] How to practice Leetcode
BUG FREE / CODING STYLE
Blog them.
Whenever you submit a solution, document what is the mistake and try to remember common mistakes
When you do a new problem, see if you make same mistake again. Document old and new mistakes until bug free
Summarize your approach with one sentence
Always check Nullness/Length/IndexOutOfBounds
Use memory curve
Practice by tags
Use lintCode to test coding style
Blog them.
Whenever you submit a solution, document what is the mistake and try to remember common mistakes
When you do a new problem, see if you make same mistake again. Document old and new mistakes until bug free
Summarize your approach with one sentence
Always check Nullness/Length/IndexOutOfBounds
Use memory curve
Use lintCode to test coding style
[Leetcode] Construct Binary Tree from Preorder and Inorder Traversal / Construct Binary Tree from Inorder and Postorder Traversal
https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal
1. Line 9, definitely check null of inputs
2. Line 12, pop() pops last element, pop(0) pops from beginning
3. Line 12, you want to create a root. cuz preorder and inorder only contains int
4. Line 15,16, build left subtree then right subtree. For constructing b-tree from postorder and inorder, build right sub tree first then left subtree
1. line 8, old drill, check inputs
2. line 11, we are using postorder to build b-tree. root node locates at the end of postorder
3. line 14/15, build right sub tree first, then left sub tree.
1. Line 9, definitely check null of inputs
2. Line 12, pop() pops last element, pop(0) pops from beginning
3. Line 12, you want to create a root. cuz preorder and inorder only contains int
4. Line 15,16, build left subtree then right subtree. For constructing b-tree from postorder and inorder, build right sub tree first then left subtree
1. line 8, old drill, check inputs
2. line 11, we are using postorder to build b-tree. root node locates at the end of postorder
3. line 14/15, build right sub tree first, then left sub tree.
Subscribe to:
Comments (Atom)