[LeetCode] Next Permutation (Java)

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 extra memory. Here are some examples. Inputs are in the left-hand column and … Read more

[LeetCode] Divide Two Integers (Java)

Divide two integers without using multiplication, division and mod operator. Analysis We can keep subtract divisor from dividend until dividend is smaller than 0, than count the subtract numbers. But it will costs a very long time if the divisor is very small comparing to dividend. Shift can be used to solve this problem. We … Read more

[LeetCode] Merge k Sorted Lists (Java)

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Analysis At first I thought this problem was quite easy. We can just pick the smallest one from all heads of lists and then connect it to the final list. But the complexity of this algorithm will be O(n2k), in which … Read more

[LeetCode] Letter Combinations of a Phone Number (Java)

Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below.

Note: Although the above answer is in lexicographical order, your answer could be in any order you want. Analysis It’s a easy question. But we … Read more

Create shortcut in Ubuntu

We may install some software manually. For example, we can run the Idea Intellij by running idea.sh. But it’s not so convenient.  So we can create a shortcut for the problem. Create a Idea.desktop file on the desktop. The content is as follow.

You may need to change the paths in the file and … Read more

[LeetCode] Longest Common Prefix (Java)

Write a function to find the longest common prefix string amongst an array of strings. Analysis This is a simple problem. We can just check for each position of every string in the string array. But we need to take care of some strings that is shorter than others. Since there is two loops, we … Read more