5-Minutes Guide for Commonly Used Linux Commands

I’m not a serious Linux user, but sometimes I need to use Linux. In a long time, I frequently searched a limited number of Linux commands. So I think it is a good idea to list those frequently-used ones and remember them finally. This definitely improved my work effectiveness. Here is my list. 1. cp/scp … Read more

LeetCode – Expressive Words (Java)

Sometimes people repeat letters to represent extra feeling, such as “hello” -> “heeellooo”, “hi” -> “hiiii”. In these strings like “heeellooo”, we have groups of adjacent letters that are all the same: “h”, “eee”, “ll”, “ooo”. For some given string S, a query word is stretchy if it can be made to be equal to … Read more

Enter password to unlock your login keyring Ubuntu 12.10

Here is a note for how to disable this password prompt under Ubuntu 12.10. The problem looks like this whenever you open browser first time after you start your computer. Error Message: “Enter password to unlock your login keyring” Ubuntu 12.10. Alt + F2 and then type in “seahorse” Click view → keystring Right-click login … Read more

LeetCode – Find And Replace in String (Java)

To some string S, we will perform some replacement operations that replace groups of letters with new ones (not necessarily the same size). Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original … Read more

LeetCode – Wiggle Sort (Java)

Given an unsorted array nums, reorder it in-place such that nums[0] < nums[1] > nums[2] < nums[3].... Example: Input: nums = [3,5,2,1,6,4] Output: One possible answer is [3,5,1,6,2,4] Java Solution public void wiggleSort(int[] nums) { if (nums == null || nums.length <= 1) { return; }   for (int i = 1; i < nums.length; ... Read more

LeetCode – Missing Ranges (Java)

Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, upper], return its missing ranges. Example: Input: nums = [0, 1, 3, 50, 75], lower = 0 and upper = 99, Output: [“2”, “4->49”, “51->74”, “76->99”] Java Solution public List<String> findMissingRanges(int[] nums, int lower, int upper) { List<String> … Read more

Get Internal Comments By Using Eclipse JDT ASTParser

You may try to use Eclipse JDT ASTParser to parse Java source files, but cannot get the list of internal comments in the .java file. There is a method called getCommentList from the CompilationUnit class. But if you use it, you find that it returns a list of empty comments. How to get internal comments … Read more

LeetCode – Partition Labels (Java)

A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts. For example: Input: S = “ababfeefhijkh” Output: [4,4,5] Explanation: The partition is “abab”, … Read more

Java – Sort Map By Value

In Java, we can use the TreeMap class to sort a map by its keys. This class is very handy to use. However, sometimes we need to sort a map by its values. How to sort a map by its values is a most frequently asked question by Java programmers. In this post, I will … Read more

HashMap vs. TreeMap vs. Hashtable vs. LinkedHashMap

Map is one of the most important data structures in Java. In this post, I will illustrate how to use different types of maps, such as HashMap, TreeMap, HashTable and LinkedHashMap. 1. Map Overview There are 4 commonly used implementations of Map in Java SE – HashMap, TreeMap, Hashtable and LinkedHashMap. If we use only … Read more

HashSet vs. TreeSet vs. LinkedHashSet

A Set contains no duplicate elements. That is one of the major reasons to use a set. There are 3 commonly used implementations of Set: HashSet, TreeSet and LinkedHashSet. When and which to use is an important question. In brief, if you need a fast set, you should use HashSet; if you need a sorted … Read more

LeetCode – LRU Cache (Java)

Design and implement a data structure for Least Recently Used (LRU) cache, which supports get and put. Analysis The key to solve this problem is using a double linked list which enables us to quickly move nodes. The LRU cache is a hash table of keys and double linked nodes. The hash table makes the … Read more

LeetCode – Palindrome Partitioning (Java)

Problem Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = “aab”, Return [ [“aa”,”b”], [“a”,”a”,”b”] ] 1. Depth-first Search public ArrayList<ArrayList<String>> partition(String s) { ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();   if (s == null || s.length() … Read more