Skip to main content
Advanced Search
Search Terms
Content Type

Exact Matches
Tag Searches
Date Options
Updated after
Updated before
Created after
Created before

Search Results

11 total results found

0009 - Palindrome Number(回文數)

寫Code刷題 LeetCode - Easy

大意說明 簡單來說就是找到類似於  121 的回文數(就是往前讀往後讀都是 121,英文會長得類似是 abcba 這種東東) 自己的思考過程(逆向字串解) 有幾種想法,一開始先想到透過轉成字串陣列,然後用迴圈做起頭和尾巴的不斷比較,迴圈範圍為字串陣列長度  / 2。 但很顯然地這個會先碰到不同語言對於除法小數的問題,導致無法過關。 例如以下 Python Code 就會卡到 / 2 的問題: class Solution: def isPalindrome(self, x: int) -> b...

刷題狀態
需要再複習

0013 - Roman to Integer

寫Code刷題 LeetCode - Easy

大意說明 題幹給了羅馬數字的轉換規則: Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 還有這一段 I can be placed before V (5) and X (10) to make 4 and 9.  X can be placed before...

刷題狀態
需要再複習

0014 - Longest Common Prefix

寫Code刷題 LeetCode - Easy

大意說明 找出一組字串陣列中,相同字串的部份。 例如 ["flower","flow","flight"] 的結果是 fl ,["dog","racecar","car"] 的結果是空字串(沒有相同的部份) 解題思路 想不到,所以參考了答案 首先先做字串 list 的排序,原因是字串經過排序之後,一定是由各字串的字母一路排上去,所以最不一樣的肯定在最後面,這樣就可以把比較範圍縮小(也比較不會不知所措) 接著就是第一個字串跟最後一個字串比較,然後用長度最小的字串長度當作迴圈結束條件之一 如果比到一半發現...

刷題狀態
需要再複習

0020 - Valid Parentheses

寫Code刷題 LeetCode - Easy

大意描述 匹配小中大括號('(', ')', '{', '}', '[' and ']' )沒了 範例最多給成 "()[]{}" 但實際上還有類似 "{()}" 這種東西,所以不要偷懶 :Kappa: 個人想法 直接用 Stack 的觀念,每次都把暫存在 Stack 內的東西拿出來比較比較,沒有匹配就兩兩丟 Stack,符合就丟掉,直到 Stack 為空代表語法正確: class Solution(object): def isValid(self, s): """ ...

刷題狀態
需要再複習

0021 - Merge Two Sorted Lists

寫Code刷題 LeetCode - Easy

大意 就是把已經排序的兩個 LinkedList 合併到一個 LinkedList,且要保持順序 實際作法 由於自己做出來都是 Timeout,應該是哪裡做錯了,以下附上正確的 Code: # Definition for singly-linked list. class ListNode(object): def __init__(self, val=0, next=None): self.val = val self.next = next cla...

刷題狀態
需要再複習

0026 - Remove Duplicates from Sorted Array

寫Code刷題 LeetCode - Easy

大意 給出一個由小排到大的整數陣列,把裡面重複的數字移除後,回傳陣列剩餘整數數量 K 一個示範的輸出輸入 case: Input: nums = [0,0,1,1,1,2,2,3,3,4] Output: 5, nums = [0,1,2,3,4,_,_,_,_,_] Explanation: Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectivel...

刷題狀態
需要再複習

0027 - Remove Element

寫Code刷題 LeetCode - Easy

大意 移除陣列裡的特定數字,回傳剩餘數量的整數。 輸出不看排序,只要內容對就好,例如以下題幹: Input: nums = [0,1,2,2,3,0,4,2], val = 2 Output: 5, nums = [0,1,4,0,3,_,_,_] Explanation: Your function should return k = 5, with the first five elements of nums containing 0, 0, 1, 3, and 4. Note that the ...

刷題狀態
需要再複習

0088 - Merge Sorted Array

寫Code刷題 LeetCode - Easy

大意來說 其實還滿簡單的...如果你排序演算法都沒有忘記的話 直接看輸出: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Explanation: The arrays we are merging are [1,2,3] and [2,5,6]. The result of the merge is [1,2,2,3,5,6] with the underlined elements ...

刷題狀態
需要再複習

0028 - Find the Index of the First Occurrence in a String

寫Code刷題 LeetCode - Easy

大意 找出目標字串片段第一次出現的起始 index 例如 mississippi ,目標字串為 issip,那 index 要回傳為 4 個人思考 因為經常 Time out,我不知道是哪裡出了問題。 最初是這樣寫的,但是在測資上爆掉了: class Solution { public int strStr(String haystack, String needle) { int sameCount = 0; int lastSuccess = 0; ...

刷題狀態
需要再複習

0058 - Length of Last Word

寫Code刷題 LeetCode - Easy

大意 有一串以空格隔開的字句,求最後一個單字的長度。 例如: Input: s = " fly me to the moon " Output: 4 Explanation: The last word is "moon" with length 4. 個人想法 從  index = 1 開始往前看,往前是確認前面是不是空格,而當前 index 卻不是空格,那這樣計數器需要先 reset。 否則,看到不是空格就一路加下去,直到跳出迴圈為止。 當然,長度小於 2 的字串要先排除掉。 ...

刷題狀態
需要再複習

0066 - Plus One

寫Code刷題 LeetCode - Easy

大意 有一個整數陣列,求裡面數值 +1 後的狀況 例如: Input: digits = [1,2,3] Output: [1,2,4] Explanation: The array represents the integer 123. Incrementing by one gives 123 + 1 = 124. Thus, the result should be [1,2,4]. 或是 Input: digits = [9] Output: [1,0] Explanation: ...

刷題狀態
需要再複習