https://leetcode.com/problems/path-sum-ii/ Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ \ …
Monthly Archives: December 2015
Leetcode 113: Path Sum II
https://leetcode.com/problems/path-sum-ii/ Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2], [5,8,4,5] ] …
Leetcode 242: valid anagram
https://leetcode.com/problems/valid-anagram/ Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = “anagram”, t = “nagaram”, return true.s = “rat”, t = “car”, return false. Note:You may assume the string contains only lowercase alphabets. Follow up:What if the inputs contain unicode characters? How would you …
Leetcode 115: Distinct Subsequences
https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" …
Create 2D array in Python
I used to create 2D zero array by the following way, for example: arr = [[0] * 3] * 4 However, `arr` actually references the list [0,0,0] 4 times. If you set `arr[1][1] = 5`, for example, you will find all “other” lists in `arr` have 5 then. >>> arr[1][1] = 5 >>> arr [[0, …
Leetcode 65: valid number
https://leetcode.com/problems/valid-number/ 65. Valid Number Total Accepted: 38767 Total Submissions: 328141 Difficulty: Hard Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one. …
Use SSH tunnel and Firefox for proxy
1.Use a specified port (e.g., 12345) for SSH SOCKS server: ssh -D 12345 user@host.domain 2. Go to the setting menu in Firefox, then Advanced->Network->Connection->Settings 3.Check the “Manual proxy configuration”, fill in SOCKS host (127.0.0.1) and port (your specified port, 12345 in our example) 4. Also, type in “about:config” in the address bar in Firefox, change …