Computer Science Archives

My dream!

  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...