C++
LeetCode: 461-Hamming Distance 解題紀錄
題目
The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, return the Hamming distance between them.Read More »LeetCode: 461-Hamming Distance 解題紀錄
LeetCode: 24-Swap Nodes in Pairs 解題紀錄
題目
Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)
Read More »LeetCode: 24-Swap Nodes in Pairs 解題紀錄LeetCode: 22-Generate Parentheses 解題紀錄
題目
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Read More »LeetCode: 22-Generate Parentheses 解題紀錄LeetCode: 121-Best Time to Buy and Sell Stock 解題紀錄
You are given an array prices where prices[i] is the price of a given stock on the ith day.
You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.
Read More »LeetCode: 121-Best Time to Buy and Sell Stock 解題紀錄[C++] 在 string 字串中使用 find() 查找字串
C++ 所提供的 STL 中的 string
模板,在處理字串方面非常方便。今天要紀錄,便是在 string
字串中,如何查找特定的文字、字串。
[C++] 使用 typeid() 確認變數資料型態
在 C++ 中,我們可以很清楚自己所定義的變數的資料型態;然而,對於第三方函式庫或是一些外部文件所傳入的參數,有時恐怕不是那麼有把握。
Read More »[C++] 使用 typeid() 確認變數資料型態LeetCode: 38-Count and Say 解題紀錄

題目
The count-and-say sequence is a sequence of digit strings defined by the recursive formula:
- countAndSay(1) = "1"
- countAndSay(n) is the way you would "say" the digit string from countAndSay(n-1), which is then converted into a different digit string.
To determine how you "say" a digit string, split it into the minimal number of groups so that each group is a contiguous section all of the same character. Then for each group, say the number of characters, then say the character. To convert the saying into a digit string, replace the counts with a number and concatenate every saying.
Given a positive integer n, return the nth term of the count-and-say sequence.
Example:
Input: n = 1
Output: "1"
Explanation: This is the base case.
Input: n = 4
Output: "1211"
Explanation:
countAndSay(1) = "1"
countAndSay(2) = say "1" = one 1 = "11"
countAndSay(3) = say "11" = two 1's = "21"
countAndSay(4) = say "21" = one 2 + one 1 = "12" + "11" = "1211"
Read More »LeetCode: 38-Count and Say 解題紀錄