Leetcode 快速複習的題目
個人刷leetcode地方,不一定每題都為最佳最速解
多為 'Top Interview 150' & 'blink 75' 的選題,其中同一題目會出現在不同類型,所以會重複
多為 'Top Interview **150'** & 'blink 75' ****的選題,其中同一題目會出現在不同類型,所以會重複
下方勾勾完全沒作用,單純複習時方便,但重新整理或離開就刷新
演算法Binary Search入門
Leetcode-34-Find-First-and-Last-Position-of-Element-in-Sorted-Array
Leetcode-35-Search-Insert-Position
Leetcode-74-Search-a-2D-Matrix
進階
Depth-First Search Breadth-First Search入門
Leetcode-100-Same-Tree
Leetcode-101-Symmetric-Tree
Leetcod ...
coding 前python快速複習公式
linknode
好處 插入只要O(1)
壞處 訪問要O(n)
full binary tree v.s. complete binary tree
一些公式/函數sort所有使用公式進行排列的時間複雜度 都是 O(nlogn)
123456789sorted_numbers = sorted(numbers)# 逆序排序sorted_numbers_desc = sorted(numbers, reverse=True)#對原列表進行numbers = [5, 2, 9, 1, 5, 6]numbers.sort()print(numbers) # 輸出: [1, 2, 5, 5, 6, 9]
poppop() 方法從列表中移除並返回指定位置的元素,如果不指定索引,則默認移除並返回列表的最後一個元素。
123456789101112131415person = {"name": "Alice", "age": 25, "city": "New York" ...
Leetcode#300. Longest Increasing Subsequence
ProblemGiven an integer array nums, return the length of the longest strictly increasing
subsequence
.
Example 1:
1234Input: nums = [10,9,2,5,3,7,101,18]Output: 4Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
Example 2:
123Input: nums = [0,1,0,3,2,3]Output: 4
Example 3:
123Input: nums = [7,7,7,7,7,7,7]Output: 1
Constraints:
1 <= nums.length <= 2500
104 <= nums[i] <= 104
Follow up: Can you come up with an algorithm that runs in O(n log( ...
Leetcode#949. Largest Time for Given Digits
ProblemGiven an array arr of 4 digits, find the latest 24-hour time that can be made using each digit exactly once.
24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.
Return the latest 24-hour time in "HH:MM" format. If no valid time can be made, return an empty string.
Example 1:
1234Input: arr = [1,2,3,4]Output: "23:41"Explanation: The valid 24-hour times ...
Leetcode#134. Gas Station
ProblemThere are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations.
Given two integer arrays gas and cost, return the starting gas station’s index if you can travel around the circuit once in the clockwise direction, otherwise return -1. If there exists a s ...
Leetcode#133. Clone Graph
ProblemGiven a reference of a node in a connected undirected graph.
Return a deep copy (clone) of the graph.
Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors.
12345class Node { public int val; public List<Node> neighbors;}
Test case format:
For simplicity, each node’s value is the same as the node’s index (1-indexed). For example, the first node with val == 1, the second node with val == 2, and so on. The graph is represented in the te ...
Leetcode#205. Isomorphic Strings
ProblemGiven two strings s and t, determine if they are isomorphic.
Two strings s and t are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.
Example 1:
Input: s = “egg”, t = “add”
Output: true
Explanation:
The strings s and t can be made identical by:
Mapping 'e' to 'a ...
Leetcode#383. Ransom Note
ProblemGiven two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.
Each letter in magazine can only be used once in ransomNote.
Example 1:
123Input: ransomNote = "a", magazine = "b"Output: false
Example 2:
12Input: ransomNote = "aa", magazine = "ab"Output: false
Example 3:
123Input: ransomNote = "aa", magazine = "aab"Output: true
Constraints:
1 <= ...
Leetcode#20. Valid Parentheses
ProblemGiven a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Every close bracket has a corresponding open bracket of the same type.
Example 1:
123Input: s = "()"Output: true
Example 2:
123Input: s = "()[]{}&q ...
Leetcode#1319. Number of Operations to Make Network Connected
ProblemThere are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a connection between computers ai and bi. Any computer can reach any other computer directly or indirectly through the network.
You are given an initial computer network connections. You can extract certain cables between two directly connected computers, and place them between any pair of disconnected computers to make them directly connecte ...