Description:

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.

Example…

Description:

Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.

Example 1:

Example 2:

Example 3:

Example 4:

Example 5:

Constraints:

  • 1 <= n <= 231 - 1

C code solution:

Description:

You are given two binary trees root1 and root2.

Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule…

名詞解釋 — Race Condition
多個processes or threads同時存取共享資源,系統依排程次序執行,而造成資料不正確的問題發生。

假設今天有兩個thread,一個負責讀取變數然後加一,另一個負責讀取變數乘以二,在期望之下應該都可以正常執行。但在race condition下就有可能發生其中一個thread還沒write,但 …

Description:

Reverse bits of a given 32 bits unsigned integer.

Example 1:

Example 2:

Constraints:

  • The input must be a binary string of length 32

C code solution:

利用指標,把原本的結構變數串起來。

在第一個結構後面加一個指標、讓它指向下一個結構;在第二個結構後面,再加一個指標,讓它指向下一個結構… 依次連接。

透過這樣的方式,能讓每個能彈性擴充。

當我們想在 Tzuyu 和 Mina 之間插入一個 Sana 時,就讓 Tzuyu 指向 Sana,再讓 Sana 指向後面 Mina。

各個Sorting algorithm的複雜度:

Insertion Sort:
從 i=1 做到 i=n-1,每一round拿現在這個數與前面的數相比,若數字比前面的小,則將前面的數往後移,直到找到比它小的數,在插入比它小的數字的下一個位置。由於此方法從左邊開始,然後每一次數字的左邊一定是個被sort好的subarray,所以此方法不怕插入到不對 …

Samuel Liu

Hi I am Samuel

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store