原创 No.187 - LeetCode480. Sliding Window Median - 經典 - 滑動窗口內的中位數

所有求窗口內中位數的問題,一般採用大小堆處理 這裏對每個大小堆維護一個哈希,來標記已刪除的元素,並同時維護一個容量值,標記實際元素個數,來保證大小堆平衡。 class Solution { public: priori

原创 No.188 - LeetCode808. Soup Servings - 概率數學+dp

因爲A和B減少的期望不同,所以隨着N無限增大,A先減少到0的概率無限接近於1 題目要求精度爲10e-6以內,具體找概率何時精度高於10e-6通過遍歷N和dfs打表來看,基本上N>5000就可以。 然後dp思路 有個trick,就

原创 go:自定義結構體排序,結構體二級排序

go 的自定義排序 type entity struct{ Id int64 UserLongtitude float64 UserLatitude float64 Longitude float64 Latitude

原创 No.191 - LeetCode59. Spiral Matrix II - 經典 - 蛇形數字 - 入門Coding

class Solution { public: vector<vector<int>> generateMatrix(int n) { vector<int> dirx,diry; dir

原创 No.190 - LeetCode836. Rectangle Overlap - 幾何 - 整點矩形相交判斷

條件:必須是整點矩形 思路:兩個矩形左下點中的右上點,必須在兩個矩形右上點中的左下點的左下側。 class Solution { public: bool isRectangleOverlap(vector<int>& r

原创 SQL1: LeetCode175. Combine Two Tables - left join - 左連接實例

# Write your MySQL query statement below Select Person.FirstName, Person.LastName, Address.City, Address.State Fr

原创 No.189 - LeetCode945. Minimum Increment to Make Array Unique - 數組題

每次操作,任意一個元素加1,使所有元素不同。 數組題,由於數據規模較小,直接排序處理即可。 class Solution { public: int minIncrementForUnique(vector<int>& A

原创 No.186 - LeetCode326 - 3的冪

當輸入數字在一定範圍內時: 可以直接取範圍內最大3的冪,對輸入取模: class Solution { public: bool isPowerOfThree(int n) { return (n > 0)

原创 No185 - Leetcode342 - 4的冪特徵

首先,2的冪特徵: 1,2,4,8,16… 二進制即0001,0010,0100,1000… 所以, bool is2power(int num){ return (num>0) && (num&(num-1)) == 0

原创 No.171 - LeetCode1302

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNo

原创 No.176 - LeetCode1309

class Solution { public: string freqAlphabets(string s) { int N = s.length(); string ans = "";

原创 No.158 - LeetCode166 - 分數變小數(經典)- Fraction to Recurring Decimal

總結一下: 很多邊界問題,有些難處理。 處理負數 處理INT_MIN溢出 無限循環的起始位置 class Solution { public: string fractionToDecimal(int numerato

原创 Mac:配置.bash_profile不生效

遇到問題:.bash_profile換了終端不生效 mac終端類型有兩種,zsh和bash, 其中,bash初始化默認.bash_profile zsh初始化默認.zshrc 我的Catalina系統默認zsh終端,所以.bash

原创 No.159 - LeetCode1290

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNo

原创 Mac 在操作系統文件時遇到Read-only file system不能mv或cp

原因:Mac電腦啓用了SIP(System Integrity Protection),增加了rootless機制,導致即使在root權限下依然無法修改文件。 方法1:關閉該保護機制: 1)重啓,過程中按住 command+R,