原创 牛客網刷題3--python

機器人的運動範圍 地上有一個m行和n列的方格。一個機器人從座標0,0的格子開始移動,每一次只能向左,右,上,下四個方向移動一格,但是不能進入行座標和列座標的數位之和大於k的格子。 例如,當k爲18時,機器人能夠進入方格(35,37

原创 Leetcode--Tree(python)

98. Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST). Assume a

原创 Leetcode--Binary Search(python)

4. Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the m

原创 Leetcode--Backtracking(python)

10. Regular Expression Matching Given an input string (s) and a pattern §, implement regular expression matching wi

原创 牛客網刷題--python

安置路燈 題目描述 小Q正在給一條長度爲n的道路設計路燈安置方案。 爲了讓問題更簡單,小Q把道路視爲n個方格,需要照亮的地方用’.'表示, 不需要照亮的障礙物格子用’X’表示。 小Q現在要在道路上設置一些路燈, 對於安置在pos位

原创 Leetcode--Array (python)

4. Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the m

原创 Leetcode--堆棧、隊列(python)

最小棧 設計一個支持 push,pop,top 操作,並能在常數時間內檢索到最小元素的棧。 push(x) – 將元素 x 推入棧中。 pop() – 刪除棧頂的元素。 top() – 獲取棧頂元素。 getMin() – 檢索棧

原创 Leetcode--常見算法題

合併兩個有序數組 給定兩個有序整數數組 nums1 和 nums2,將 nums2 合併到 nums1 中,使得 num1 成爲一個有序數組。 說明: 初始化 nums1 和 nums2 的元素數量分別爲 m 和 n。 你可以假設

原创 Leetcode--前綴樹Trie(python)

實現 Trie (前綴樹) 實現一個 Trie (前綴樹),包含 insert, search, 和 startsWith 這三個操作。 示例: Trie trie = new Trie(); trie.insert(“apple

原创 Leetcode--Dynamic Programming(python)

5.Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You may assume that

原创 Leetcode--Hash Table(python)

3. Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without

原创 Leetcode--數組(python)

乘積最大子序列 給定一個整數數組 nums ,找出一個序列中乘積最大的連續子序列(該序列至少包含一個數)。 示例 1: 輸入: [2,3,-2,4] 輸出: 6 解釋: 子數組 [2,3] 有最大乘積 6。 示例 2: 輸入: [

原创 常見概率題

從n個數中生成m個不重複的隨機數 import random for i in range(n): x = random.randint(i, n) if x < m: print(i) m -= 1 由這個for循環

原创 Leetcode--Math(python)

12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol

原创 LeetCode--遞歸(python)

兩兩交換鏈表中的節點 給定一個鏈表,兩兩交換其中相鄰的節點,並返回交換後的鏈表。 你不能只是單純的改變節點內部的值,而是需要實際的進行節點交換。 示例: 給定 1->2->3->4, 你應該返回 2->1->4->3. 解法 首先