Stone Game 題目連結 兩種情況 大數字在前或後==> alice 可以先選 大數字在中間 ==> 由於alice 選數字時數量一定是...
Smallest String Starting From Leaf 題目連結 用bfs來做 1.先移路往左走(直到左邊是null),刪掉當下的點(往回走)...
Add One Row to Tree (623) 在原本的二元樹的某一層插入新節點(後面一樣是舊節點) 用bfs遍歷樹(直到到要補的層前),插入左值與右值...
[LeetCode] 875 - Koko Eating Bananas Problem 給定一個有 n 堆香蕉的陣列 piles (第 i 堆的數量為 pil...
Cheapest Flights Within K Stops 很久沒有發文了,雖然還是有寫題的習慣,但寫解題真的有點懶(誤 總而言之,最後還是決定寫一下,畢竟...
前言 這題標準運用了二分搜尋法,演算法通常需要使用二分思想,即每次能夠排除一半的範圍,快速的找出陣列中所要求的元素位置,這樣時間複雜度可達 O(log n)...
Given two strings s1 and s2, return true if s2 contains a permutation of s1, or...
Given an array of integers temperatures represents the daily temperatures, retur...
You are given an integer array cost where cost[i] is the cost of ith step on a s...
Given a string s, return the longest palindromic substring in s. 給一個 string 回傳該...
You are a professional robber planning to rob houses along a street. Each house...
You are a professional robber planning to rob houses along a street. Each house...
Given two integer arrays preorder and inorder where preorder is the preorder tra...
Given the root of a binary tree, invert the tree, and return its root. 給一個 tree...
Given the head of a linked list, remove the nth node from the end of the list an...
You are given the head of a singly linked-list. The list can be represented as:...
Given the head of a singly linked list, reverse the list, and return the reverse...
You are given the heads of two sorted linked lists list1 and list2. Merge the tw...
There is an integer array nums sorted in ascending order (with distinct values)....
Suppose an array of length n sorted in ascending order is rotated between 1 and...
You are given a string s and an integer k. You can choose any character of the s...
Given a string s, find the length of the longest substring without repeating cha...
Given two strings s and t, return true if t is an anagram of s, and false otherw...
Given an integer array nums, return true if any value appears at least twice in...
歐氏定理: 「英文文法跟中文相反」。以下這一段英文,最重要的是在「最後面」(choose an element of the array and increme...
MediumRelated Topics: Hash Table / Math / StringLeetCode Source 解題想法 LeetCode...
歐氏定理: 「英文文法跟中文是相反的。」Return true if s is an acronym of words, and false otherwise...
HardRelated Topics: Array / Two Pointers / Dynamic Programming / Stack / Monoto...
前言 這題是一題動態規劃問題,目標是擷取不連續的元素,全部相加起來選出最優解,因只用了一層迴圈,時間複雜度可估 O(n),這裡有 JAVA 和 Python...
HardRelated Topics: Array / GreedyLeetCode Source 解題想法 首先先確認 len(ratings),如果小於...