Open in app

Sign in

Write

Sign in

Samuel Liu
Samuel Liu

1 Follower

Home

About

Oct 7, 2021

[C] Move a range of bits to a new range in a number

Description: 此function可以將某數某範圍的bits移到另一個範圍 void move_bits(int *a, int l, int new_l, int num){ if(num == 0) return; //create get_mask int get_mask = 0; int …

C

3 min read

C

3 min read


Oct 5, 2021

[Leetcode 20] Valid Parentheses

Description: Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Example…

C

1 min read

C

1 min read


Oct 4, 2021

[Leetcode 693] Binary Number with Alternating Bits

Description: Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Input: n = 5 Output: true Explanation: The binary representation of 5 is: 101 Example 2: Input: n = 7 Output: false Explanation: The binary representation of 7 is: 111. Example 3: Input: n = 11 Output: false Explanation: The binary representation of 11 is: 1011.

C

1 min read

C

1 min read


Oct 3, 2021

[Leetcode 617] Merge Two Binary Trees

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…

C

2 min read

[Leetcode 617] Merge Two Binary Trees
[Leetcode 617] Merge Two Binary Trees
C

2 min read


Sep 29, 2021

同步問題 Synchronization

名詞解釋 — Race Condition 多個processes or threads同時存取共享資源,系統依排程次序執行,而造成資料不正確的問題發生。 假設今天有兩個thread,一個負責讀取變數然後加一,另一個負責讀取變數乘以二,在期望之下應該都可以正常執行。但在race condition下就有可能發生其中一個thread還沒write,但 …

14 min read

同步問題 Synchronization
同步問題 Synchronization

14 min read


Sep 28, 2021

[Leetcode 190] Reverse Bits

Description: Reverse bits of a given 32 bits unsigned integer. Example 1: Input: n = 00000010100101000001111010011100 Output: 964176192 (00111001011110000010100101000000) Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000. Example 2: Input: n = 11111111111111111111111111111101 Output: 3221225471 (10111111111111111111111111111111) Explanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.

C

1 min read

C

1 min read


Sep 28, 2021

[C] Linked list

利用指標,把原本的結構變數串起來。 在第一個結構後面加一個指標、讓它指向下一個結構;在第二個結構後面,再加一個指標,讓它指向下一個結構… 依次連接。 透過這樣的方式,能讓每個能彈性擴充。 當我們想在 Tzuyu 和 Mina 之間插入一個 Sana 時,就讓 Tzuyu 指向 Sana,再讓 Sana 指向後面 Mina。

3 min read

[C] Linked list
[C] Linked list

3 min read


Sep 28, 2021

[C] 各種Sorting

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

C

8 min read

[C] 各種Sorting
[C] 各種Sorting
C

8 min read


Sep 27, 2021

[Leetcode 700] Search in a Binary Search Tree

Description: You are given the root of a binary search tree (BST) and an integer val. Find the node in the BST that the node’s value equals val and return the subtree rooted with that node. If such a node does not exist, return null. Example 1: Input: root =…

C

2 min read

[Leetcode 700] Search in a Binary Search Tree
[Leetcode 700] Search in a Binary Search Tree
C

2 min read


Sep 27, 2021

[Leetcode 701] Insert into a Binary Search Tree

Description: You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST. Notice that there may exist…

C

2 min read

[Leetcode 701] Insert into a Binary Search Tree
[Leetcode 701] Insert into a Binary Search Tree
C

2 min read

Samuel Liu

Samuel Liu

1 Follower

Hi I am Samuel

Help

Status

About

Careers

Blog

Privacy

Terms

Text to speech

Teams