原创 【C/C++】【模板和泛型】成員函數模板

普通類的成員函數模板 不管是普通類還是類模板,它的成員函數可以是一個函數模板(成爲成員函數模板)。不可以是虛函數,否則編譯器會報錯。 //普通類的成員函數模板 class A { public: template<typename T>

原创 【C/C++】【模板與泛型】typename

typename的使用場合 模板定義中,表明其後的模板參數是類型參數 template<typename T, int a, int b> //typename後跟的是一個類型 int funcadd(T c){...} templ

原创 【C/C++】【模板和泛型】using定義模板別名

using定義模板別名 using //typedef:一般用來定義類型別名 typedef unsigned int uint_t; uint_t abc; //map<string, int> typedef map<string,

原创 【算法】【圖】拓撲排序

鄰接矩陣 #include <iostream> #include <queue> #include <algorithm> #include <set> using namespace std; int n, m; vector<i

原创 【算法】【棧】棧相關題目

字符串解碼 題目鏈接:https://leetcode-cn.com/problems/decode-string/ class Solution { public: string decodeString(string s) {

原创 【算法】【單調棧】Leetcode高頻面試題

每日溫度 題目鏈接:https://leetcode-cn.com/problems/daily-temperatures/ class Solution { public: vector<int> dailyTemperature

原创 【C/C++】【類和對象】計算類所佔的字節數

空類 空類 #include <iostream> using namespace std; class Base { void f(){}; }; int main() { cout << sizeof(Base) <

原创 【算法】【單調棧】單調棧

單調棧 找每個數左邊離它最近的比它大/小的數 模板 stack<int> st; for(int i = 1; i <= n; i++) { while(st.size() > 0 && x <= st.top()) st.po

原创 【算法】【雙指針】Leetcode雙指針題目總結

壓縮字符串 題目鏈接:https://leetcode-cn.com/problems/string-compression/ class Solution { public: int compress(vector<char>&

原创 【算法】【字符串】Leetcode哈希表相關高頻面試題

字母異位詞分組 題目鏈接:https://leetcode-cn.com/problems/group-anagrams/ class Solution { public: vector<vector<string>> groupA

原创 【算法】【雙指針】雙指針

雙指針 對於一個序列,用兩個指針維護一段區間; 對於兩個序列,維護某種次序,比如歸併排序中合併兩個有序序列的操作; for(int i = 0, j = 0; j < n; j++) { //當前維護的區間不滿足條件,i向前

原创 【算法】【字符串】C語言常用庫函數實現

strcpy #include <iostream> #include <assert.h> using namespace std; char * my_strcpy(char* str1,const char* str2) {

原创 【算法】【二分】Leetcode二分問題總結

在排序數組中查找數字 題目鏈接:https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/ class Solution { public:

原创 【算法】【字符串】Leetcode滑動窗口相關題目

滑動窗口 維護一個窗口,不斷滑動; for(int l = 0, r = 0; r < s.size();) { //增大窗口 win.add(s[r]); r++; //窗口右移

原创 【算法】【二分】二分查找總結

找精確值模板 int l = 0, r = n - 1; while(l <= r) { int mid = l + r >> 1; if(arr[mid] < target) l = mid + 1; else i