iT邦幫忙

leetcode相關文章
共有 1099 則文章

技術 [LeetCode筆記] 34. Find First and last Position of Element in Sorted Array

前言   這題標準運用了二分搜尋法,演算法通常需要使用二分思想,即每次能夠排除一半的範圍,快速的找出陣列中所要求的元素位置,這樣時間複雜度可達 O(log n)...

技術 [LeetCode] 13. Roman to Integer

MediumRelated Topics: Hash Table / Math / StringLeetCode Source 解題想法 LeetCode...

技術 Leetcode 中文。你可能只花一分鐘寫完程式碼,但是比較困難在於閱讀英文題目。

歐氏定理: 「英文文法跟中文是相反的。」Return true if s is an acronym of words, and false otherwise...

技術 [LeetCode] 42. Trapping Rain Water

HardRelated Topics: Array / Two Pointers / Dynamic Programming / Stack / Monoto...

技術 [LeetCode 筆記] 198. House Robber

前言   這題是一題動態規劃問題,目標是擷取不連續的元素,全部相加起來選出最優解,因只用了一層迴圈,時間複雜度可估 O(n),這裡有 JAVA 和 Python...

技術 [LeetCode] 135. Candy

HardRelated Topics: Array / GreedyLeetCode Source 解題想法 首先先確認 len(ratings),如果小於...

技術 [LeetCode] 134. Gas Station

MediumRelated Topics: Array / GreedyLeetCode Source 解題想法 這題是看之前解的方法 Python cl...

技術 [LeetCode] 238. Product of Array Except Self

MediumRelated Topics: Array / Prefix SumLeetCode Source 解題想法 這題我是看別人解法 原本以為要用...

技術 [LeetCode] 380. Insert Delete GetRandom O(1)

MediumRelated Topics: Array / Hash Table / Math / Design / RandomizedLeetCode S...

技術 [LeetCode] 274. H-Index

MediumRelated Topics: Array / Sorting / Counting SortLeetCode Source 解題想法 這題我卡...

技術 [LeetCode] 45. Jump Game II

MediumRelated Topics: Array / Dynamic Programming / GreedyLeetCode Source 解題想法...

技術 [LeetCode] 55. Jump Game

MediumRelated Topics: Array / Dynamic Programming / GreedyLeetCode Source 解題想法...

技術 [LeetCode] 122. Best Time to Buy and Sell Stock II

MediumRelated Topics: Array / Dynamic Programming / GreedyLeetCode Source 解題想法...

技術 [LeetCode] 121. Best Time to Buy and Sell Stock

EasyRelated Topics: Array / Dynamic ProgrammingLeetCode Source 解題想法 當下想到最直覺的解法...

技術 30天Leetcode挑戰(12):1535 find the last winner

碎碎念 好幾天沒寫文了,但其實每天都有上去看題(例如昨天的螞蟻相撞),也都有在跟朋友討論。這幾天有很多可以用外鄉人作法來處理的題目,感覺是蠻有趣的。 題幹 給一...

技術 [LeetCode] 189. Rotate Array

MediumRelated Topics: Array / Math / Two PointersLeetCode Source 解題想法 這裡初始化 l...

技術 [LeetCode] 169. Majority Element

EasyRelated Topics: Array / Hash Table / Divide and Conquer / Sorting / Countin...

技術 [LeetCode] 80. Remove Duplicates from Sorted Array II

MediumRelated Topics: Array / Two PointersLeetCode Source 解題想法 這題跟昨天類似,但可重複的數字...

技術 [LeetCode] 26. Remove Duplicates from Sorted Array

EasyRelated Topics: Array / Two PointersLeetCode Source 解題想法 這題有 Hint 我有看一下 XD...

技術 [LeetCode] 27. Remove Element

EasyRelated Topics: Array / Two PointersLeetCode Source 解題想法 題目除了要回傳最後 nums 的長...

技術 30天Leetcode挑戰(11):501 Fine mode in binary tree

碎碎念 好像斷更了,但沒關係,跟我一起挑戰的朋友有持續下去的樣子。今天也是一個跟閱讀測驗鬥智鬥勇的題目,而且最後搞出來的程式碼大概40行你真的是easy題目嗎....

技術 [LeetCode] 88. Merge Sorted Array

EasyRelated Topics: Array / Two Pointers / SortingLeetCode Source 解題想法 題目要求要 i...

技術 30天Leetcode挑戰(10):458 Poor pig

碎碎念 大腦不夠用了,看了答案也還沒辦法吸收,我沒有提交,這禮拜我應該少交了兩三個,都好難ㄛ哭 題幹 用最少的豬來測試毒水桶,有點像是去找哪個硬幣比較輕的腦筋急...

技術 [LeetCode 筆記] 238. Product of Array Except Self

前言   這題有點類似 Prefix Sums 的概念,目標是找到陣列中元素自己以外的所有元素的乘績,放在一個新的陣列裡,雖然有三個迴圈是 O(3n) 的時間複...

技術 30天Leetcode挑戰(9):1220. Count Vowels Permutation

碎碎念 AI已經強大到我覺得「他已經知道我在刷leetcode」了......可能我問問題的時候直接讓他知道我是要看母音吧 是說,我很想知道到底是誰在看我的文章...

技術 30天Leetcode挑戰(8):823. Binary Trees With Factors

碎碎念 這題我沒做出來,還碰到了GPT4的發問上限,相當崩潰我個人是非常賭爛這一題的,題目描述很空泛(討論區也有在罵的,所以看來不是只有我) 題幹 我自己也不是...

技術 30天Leetcode挑戰(7):779 k-th symbol in gramar

碎碎念 這是一個很棒的題目,也是我所期待遇到的東西。當然,也不排除是我太笨啦。 題幹 給予兩個數值,第一個k代表會有幾階的數,一階是0,二階是把0變成01,三階...

技術 30天Leetcode挑戰(6):1793 Maximum score of a good subarray

碎碎念 這應該是一兩天前的,但因為那幾天忙碌就沒有記下來了。這一題可難可簡單,我是先用了笨方法然後吃到超時,然後請GPT改成快一點的方法(蠻猛的) 提案 這題也...

技術 30天Leetcode挑戰(5):515 Largest value in each tree raw

碎碎念 好啦嚴格說今天的不算是碎碎念,比較像是心得分享。我發現在解這些題目的過程,我自己的思路會有很大的開拓與改變,而那些嚴格的測資也會讓我知道不可以作弊(欸)...

技術 30天Leetcode挑戰(4):342 Power of four

碎碎念 終於是easy題了......連續被電了兩天的hard(昨天的我還沒發文) 題幹 確認輸入的數字是4的平方數(也就是4^x) 解題思路 基本上就是mod...