Leetcode 5: Longest Palindromic Substring

Longest Palindromic Substring https://leetcode.com/problems/longest-palindromic-substring/ Total Accepted: 71879 Total Submissions: 343504 Difficulty: Medium Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. Code: class Solution(object): def longestPalindrome(self, s): “”” :type s: str :rtype: str “”” …

Compile Hadoop 2.7 on Eclipse on Ubuntu 15.04

Install libtool: sudo apt-get install libtool  Install protoc 2.5: http://stackoverflow.com/questions/29797763/how-do-i-install-protobuf-2-5-on-arch-linux-for-compiling-hadoop-2-6-0-using-mav Git clone hadoop-common and compile using Maven then import into Eclipse: https://wiki.apache.org/hadoop/EclipseEnvironment Make sure Eclipse uses officially supported JRE: https://wiki.apache.org/hadoop/HadoopJavaVersions, http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-add_new_jre.htm You may still find some class cannot be resolved, or some import package can’t be resolved. This is due to that Maven generates some …

Python multiprocessing map function with shared memory object as additional parameter

Suppose you want to create a bunch of processes to consume a list of elements: import multiprocessing def consume(ele): return ele ** 2 if __name__ == ‘__main__’: m_list = [9,8,7,6,5] pool = multiprocessing.Pool(processes=300) result = pool.map(consume, m_list) print result   Now, if you want to have a dictionary to be shared across processes, and pass …

Very important to set verbose output for Ubuntu User

I often mess up with Ubuntu System so much that I can’t manage to boot the system. I always end up with being stuck at the splash screen with no clue what is going on in the background. So, I suggest that for every ubuntu user you should turn on verbose output during the boot. …

Leetcode 4: Median of Two Sorted Arrays

https://leetcode.com/problems/median-of-two-sorted-arrays/ Median of Two Sorted Arrays Total Accepted: 65901 Total Submissions: 385447 Difficulty: Hard There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Let me first show the code and then show the …

Leetcode 3: Longest Substring Without Repeating Characters

https://leetcode.com/problems/longest-substring-without-repeating-characters/   Longest Substring Without Repeating Characters Total Accepted: 95017 Total Submissions: 467741 Difficulty: Medium Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating characters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length …

Leetcode 90: Find all possible subsets of a subset

https://leetcode.com/problems/subsets-ii/ Subsets II Total Accepted: 47791 Total Submissions: 170711 Difficulty: Medium Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example,If nums = [1,2,2], a solution is: [ [2], [1], [1,2,2], …

Leetcode 218: The Skyline Problem

https://leetcode.com/problems/the-skyline-problem/ The Skyline Problem A city’s skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on a cityscape photo (Figure A), write a program to output the skyline …

Leetcode 42: Trapping Rain Water

Trapping Rain Water Total Accepted: 47601 Total Submissions: 157411 Difficulty: Hard Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. https://leetcode.com/problems/trapping-rain-water/   Naive idea: traverse from left to right. left[i] means …