LeetCode – Merge k Sorted Lists (Java)

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Analysis The simplest solution is using PriorityQueue. The elements of the priority queue are ordered according to their natural ordering, or by a comparator provided at the construction time (in this case). Java Solution public ListNode mergeKLists(ListNode[] lists) … Read more

LeetCode – Permutation Sequence (Java)

The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): “123” “132” “213” “231” “312” “321” Given n and k, return the kth permutation sequence. (Note: Given n will be between 1 and 9 inclusive.) … Read more

LeetCode – Minimum Depth of Binary Tree (Java)

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Thoughts LinkedList is a queue in Java. The add() and remove() methods are used to manipulate the queue. Java Solution /** * Definition for binary … Read more

Eclipse Plug-in Development – Create a Perspective

A perspective is the container for a set of views and editors. The most commonly used perspective is probably “Java” which contains a set of views for Java development such as a package explorer, an editor, a console, etc. You can switch to another perspective by clicking “Window” -> “Open Perspective”. Switching perspectives let you … Read more

LeetCode – Maximum Subarray (Java)

Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has the largest sum = 6. Java Solution – DP The easiest way to formulate the solution of this problem is using DP. Let f(n) be the maximum … Read more