Latest / page 2

  1. LeetCode in Swift: Search Insert Position

    Problem Statement Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Here are few examples. [1,3,5,6], 5 2 [1,3,5,6], 2 1 [1,3,5,6], 7 4 [1,3,5,6], 0 0 Original LeetCode problem page My Solution Continue reading...

  2. LeetCode in Swift: Insertion Sort List

    Problem Statement Sort a linked list using insertion sort. Original LeetCode problem page My Solution in Swift Every time after inserting a list node, I use a variable to record the reference to that node. When next uninserted list node comes in, it checks from the recorded last inserted node instead of restarting the checking from the head list node. Continue reading...

  3. LeetCode in Swift: Sort List

    Problem Statement Sort a linked list in O(n log n) time using constant space complexity. Original LeetCode problem page My Solution in Swift I used a bottom-up iterative merge-sort to solve this problem with O(n log n) time efficiency and O(1) space efficiency. Note that, you cannot use traditional recursive merge-sort to tackle this problem; Continue reading...

  4. LeetCode in Swift: Evaluate Reverse Polish Notation

    Problem Statement Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples:

    Original LeetCode problem page My Solution in Swift Continue reading...

  5. Fix Python graph-tool “couldn’t recognise svg” Problem

    After I had installed graph-tool and gtk+3 via homebrew and tried to run a graph-tool demo, I came across the following problem:

    I then did a little bit Googling and found out that this was caused by a lack of SVG lib ‘librsvg’ for homebrew’s gtk installation. However, a simple homebrew installation of that lib didn’t fix Continue reading...

  6. How to Set a Key Binding in Sublime Text Based on the File Type the Command Is Running on

    In my Sublime Text 3, I use JsFormat to format my javascript source code. Its key binding follows:

    I have noticed that the JsFormat used the selector context operand to make sure that the js_format command would only run on file types “.js”, “.json” or “.html”. This is to avoid key clashes with other Continue reading...