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 …
Author Archives: czxttkl
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 …
BFGS and L-BFGS materials
Good explanation for BFGS and L-BFGS can be found in this textbook: https://www.dropbox.com/s/qavnl2hr170njbd/NumericalOptimization2ndedJNocedalSWright%282006%29.pdf?dl=0 In my own words: Gradient descent and its various variants have been proved to learn parameters well in practical unconstrained optimization problems. However, it may converge too slowly or too roughly depending on how you set learning rate. Remember the optimum in unconstrained …
Configure PySpark in Eclipse/Pydev
Go here and download some prebuilt version for spark. (So that you don’t need to compile spark locally later) Follow this slide: http://www.slideshare.net/prossblad/install-eclipse-for-sparkpython-49100874 to setup up Python interpretor/environment in Eclipes/Pydev
Recommendation System Review
Traditional Collaborative Filtering each user is represented by a O(N) length vector. N is the number of items. Therefore, user-item matrix has size O(MN). M is the number of users. for a user we want to recommend items for, we scan through user-item matrix, and find most similar k users. Based on the item vectors …
My Lempel-Ziv Compressor
Lempel-Ziv algorithm is a widely known compression algorithm. Its compression rate is proved to asymptotically reach the entropy of per symbol in the sequence to be compressed, when the length of the sequence is long enough.i.e., , where is per symbol entropy in the sequence . If, for example, you have a sequence of letters …
Graph Model Recap
I wrote a post before talking about sum-product algorithm: http://maider.blog.sohu.com/307377602.html At that time, I had fresh memory on how graph model works. However, today when I read the post again, I am lost again. Therefore, I want to recap the basic motivations of graph models. This post can serve as an intro to the old post. …