原创 Manjaro 安裝好後的配置

更換鏡像源 sudo pacman-mirrors -i -c China -m rank 添加源 [archlinuxcn] SigLevel = Optional TrustedOnly Server = https://mi

原创 Leetcode——349. Intersection of Two Arrays

題意:查找兩個vector的交集。 class Solution { public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {

原创 339A. Helpful Maths

排序的方法: 1.升序sort(s.begin(),s.end());2.降序 sort(s.begin(),s.end(),compare);字符串反轉 reverse(s1.begin(),s1.end());排序的字符串反轉需要包含

原创 Leetcode——24. Swap Nodes in Pairs

分四種情況討論:有0個,1個,2個和大於2個結點。 class Solution { public: ListNode* swapPairs(ListNode* head) { if(head==NULL||hea

原创 Leetcode——141. Linked List Cycle

遍歷過的結點的值重置爲int類型可以表示的最大值,若再次遍歷到此節點說明存在循環,若遍歷到最後一個結點(即遍歷到空)則說明沒有循環。 class Solution { public: bool hasCycle(ListNode

原创 Leetcode——747. Largest Number Greater Than Twice of Others

用最原始的方法就可以通過。 找出最大和第二大,相比,觀察結果是否大於2. class Solution { public: int dominantIndex(vector<int>& nums) { if(num

原创 Leetcode——48. Rotate Image

兩個方法: 一:先沿對角線翻折,再沿水平中線泛着 二:將每一圈旋轉四分之一個週期 //方法一:先沿着左下-右上對角線反轉,在沿着水平中線反轉 class Solution { public: void rotate(vector

原创 codeforces——D. Shovel Sale

1LL——long long類型的1,其實就是1。 #include <iostream> using namespace std; int main() { //cout<<1LL;//long long 型的1 lon

原创 Leetcode——167. Two Sum II - Input array is sorted

兩個指針,分別指向數組的開頭和末尾,和小於target則頭指針後移,和大於target則尾指針前移。 class Solution { public: vector<int> twoSum(vector<int>& numbers

原创 Leetcode——34. Search for a Range

先利用二分法找到目標,然後再目標附近向前和向後。class Solution { public: vector<int> searchRan

原创 c++ STL 集合set

0.set是一個容器,其中所包含的元素的值是唯一的。multiset中可以出現副本鍵,同一值可以出現多次。 1.使用集合首先要包含頭文件#include<set> 2.set的構造函數和析構函數         set c     產生一

原创 c++ STL--棧(stack)

1.若要使用 棧,需要有頭函數#include<stack> 2.STL容器stack成員函數         bool empty()  判斷是否爲空         void pop()  刪除棧頂元素         void pu

原创 c++ STL 向量(vector)

1.使用向量vector需要包含的頭文件#include<vector> 2.vector是一個動態數組,隨機存取任何元素都能在常數時間完成 3.vector的構造函數和析構函數       vector<TYPE> c       產生

原创 c++ STL 列表List

1.要想使用list,頭文件中要包含#include<list> 2.列表是一個線性鏈表結構(雙鏈表),數據由若干個節點構成,每個節點包含一個實際存儲的數據(信息快),一個前驅指針,一個後驅指針。 缺點:由於結構的原因,隨機檢索的性能非常

原创 Leetcode——524. Longest Word in Dictionary through Deleting

1.題意:給定一個字符串string s,同時給定另外一組字符串d。找出可以通過刪除s中的某些字符得到且同時位於d中的最長的字符串,若長度相等,按字典順序排列。 2.用到的一個方法:string中的compare 相等返回值爲0 大於返回