LeetCode
LeetCode: 1290-Convert Binary Number in a Linked List to Integer
題目
Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.
Return the decimal value of the number in the linked list.
Read More »LeetCode: 1290-Convert Binary Number in a Linked List to IntegerLeetCode: 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: 23-Merge k Sorted Lists 解題紀錄
題目
You are given an array of k
linked-lists lists
, each linked-list is sorted in ascending order.
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 解題紀錄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 解題紀錄