Install Python Package for User

If you do not have root privilege and want to install a python module, you can try the following approach:   python setup.py install –user This will install packages into subdirectories of site.USER_BASE. To check what is the value of site.USER_BASE, use:   import site print site.USER_BASE reference: https://docs.python.org/2/install/   Update 2018/01/06: using pip to …

Embedding and Heterogeneous Network Papers

Embedding methods have been widely used in graph, network, NLP and recommendation system. In short, embedding methods vectorize entities under study by mapping them into a shared latent space. Once vectorized representation of entities are learned (through either supervised or unsupervised fashion), a lot of knowledge discovery work can be done: clustering based on entity …

The expected times of tosses until you see first HTH or HTT

The problem comes from a very famous Ted Talk:  You are flipping a fair coin. What is the expected times of tosses you need to see the first “HTH” appears? What is that for the first “HTT” appears? Suppose $latex N_1$ is the random variable which counts the number of flips till we get first …

Leetcode 31: Next Permutation

31. Next Permutation Total Accepted: 87393 Total Submissions: 313398 Difficulty: Medium Contributors: Admin Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replacement must be in-place, do not allocate …

Leetcode 64: Minimum Path Sum

https://leetcode.com/problems/minimum-path-sum/ 64. Minimum Path Sum Total Accepted: 91005 Total Submissions: 247256 Difficulty: Medium Contributors: Admin Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any …

Leetcode 88: Merge Sorted Array

88. Merge Sorted Array Total Accepted: 129487 Total Submissions: 416385 Difficulty: Easy Contributors: Admin Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The …

Leetsql 196: Delete Duplicate Emails

196. Delete Duplicate Emails Total Accepted: 18532 Total Submissions: 97924 Difficulty: Easy Contributors: Admin Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. +—-+——————+ | Id | Email | +—-+——————+ | 1 | john@example.com | | 2 | bob@example.com | …

Leetcode 254: Factor Combinations

254. Factor Combinations Total Accepted: 16019 Total Submissions: 40853 Difficulty: Medium Contributors: Admin Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a function that takes an integer n and return all possible combinations of its factors. Note: You may assume …