[Python] 3.10 先覽版本開始支援 switch 功能(透過 match 語法)
switch 是一種在眾多程式語言當中都有支援的語法,跟 if-else 功能很相似,不過跟設定任意條件的 if-else 不同,switch 更是針對單一條件的不同情況來執行程式碼,在許多時候比 if-else 來得更直覺。
Read More »[Python] 3.10 先覽版本開始支援 switch 功能(透過 match 語法)switch 是一種在眾多程式語言當中都有支援的語法,跟 if-else 功能很相似,不過跟設定任意條件的 if-else 不同,switch 更是針對單一條件的不同情況來執行程式碼,在許多時候比 if-else 來得更直覺。
Read More »[Python] 3.10 先覽版本開始支援 switch 功能(透過 match 語法)最近比較多網友詢問了我關於如何透過程式在 WordPress 上發表文章,正好藉這次的機會,嘗試使用之前比較沒有研究的 REST API 來達到發表文章的目的。
Read More »[WordPress] 使用 REST API 發表文章在使用 WordPress 架設網站的過程中,我們可能早就發表了數也數不清數量的文章。那麼,若有一天,我們需要取得所有發表過的文章資訊時,究竟應該要怎麼做呢?
Read More »[WordPress] 取得所有發表過的文章一直以來,我都有使用 PyQt5 做一些簡單的小工具供自己日常使用,在我將日常生活用的筆電從 Linux 轉到 MacOS 後,這些小工具也一直都運作得很好。
Read More »[已解決][MacOS] Big Sur 11.2.1 PyQt5 的視窗無法顯示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 解題紀錄Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
Clarification:
Confused why the returned value is an integer but your answer is an array?
Note that the input array is passed in by reference, which means a modification to the input array will be known to the caller as well.
Example:
Input: nums = [1,1,2]
Output: 2, nums = [1,2]
Explanation: Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn't matter what you leave beyond the returned length.
題目輸入一個由小到大排序的陣列,我們需要回傳『沒有重複元素陣列長度』,並將這些沒有重複的元素移動至該陣列的開頭。
當然你可以選擇刪除掉重複的元素,但驗證時只會依照你回傳的長度進行該陣列的檢測。比方說你回傳 1,那麼驗證機制只會檢測陣列開頭第 1 個元素。
Read More »LeetCode: 26-Remove Duplicates from Sorted Array 解題紀錄Given the head of a linked list, remove the nth node from the end of the list and return its head.
Follow up: Could you do this in one pass?
Example:
Input: head = [1,2,3,4,5], n = 2
Output: [1,2,3,5]
本題給定一個鏈結串列(Linked List),而我們要做的,便是將倒數第 n 個元素刪除,並回傳刪除後的 Linked List。
Read More »LeetCode: 19-Remove Nth Node From End of List 解題紀錄Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.
Notice that the solution set must not contain duplicate quadruplets.
Example:
Input: nums = [1,0,-1,0,-2,2], target = 0
Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]
這個題目是 2Sum、3Sum 的衍伸版,同樣給定一個整數陣列輸入,我們要找出由四個數加總為 0 的所有組合。
Read More »LeetCode: 18-4Sum 解題紀錄Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
Example:
Input: s = "(()"
Output: 2
Explanation: The longest valid parentheses substring is "()".
Input: s = ")()())"
Output: 4
Explanation: The longest valid parentheses substring is "()()".
這個題目輸入一個只由 ‘(‘ 或是 ‘)’ 組成的字串,而我們要做的,就是判斷最長的『合理』子字串長度。
比方說, “()” 就是合理的子字串、”)(” 就是個不合理的子字串。
Read More »LeetCode: 32-Longest Valid Parentheses 解題紀錄Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.
Example:
Input: nums = [-1,2,1,-4], target = 1
Output: 2
Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
Constraints:
3 <= nums.length <= 10^3
-10^3 <= nums[i] <= 10^3
-10^4 <= target <= 10^4
這個題目跟 15 題非常相似,同樣是給定一組整數陣列輸入,不過還多給了一個目標值 target。我們需要找出 3 個數值,使其加總值越接近 target 越好。
需要注意的是,我們要返回的並不是找到的陣列,而是直接返回最接近 target 的數值。
Read More »LeetCode: 16-3Sum Closest 解題紀錄