原创 LeetCode-5. 最長迴文子串

地址:https://leetcode-cn.com/problems/longest-palindromic-substring/ 思路:一:直接暴力,遍歷迴文字符串的中心位置,在由中心位置向外展開判斷即可 二:manacher算法,

原创 LeetCode-24.兩兩交換鏈表中的節點

地址:https://leetcode-cn.com/problems/swap-nodes-in-pairs/ 思路:每次循環記錄要交換的兩節點和前一個節點,然後做交換即可 Code: #include<iostream> #inc

原创 LeetCode-27. 移除元素

地址:https://leetcode-cn.com/problems/remove-element/ 思路:覆蓋操作即可 Code: #include<iostream> #include<vector> #include<set>

原创 LeetCode-1.兩數之和

地址:https://leetcode-cn.com/problems/two-sum/ 思路:可以通過暴力枚舉,但也可以利用無序map來做 Code: #include<iostream> #include<algorithm> #

原创 LeetCode-3.無重複字符的最長子串

地址:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ 思路:可以直接暴力枚舉子串左端點,也可以枚舉子串右端點,在對左端點l

原创 LeetCode-12. 整數轉羅馬數字

地址:https://leetcode-cn.com/problems/integer-to-roman/ 思路:按照題意轉換即可 Code: #include<iostream> #include<algorithm> #inclu

原创 LeetCode-21. 合併兩個有序鏈表

地址:https://leetcode-cn.com/problems/merge-two-sorted-lists/ 思路:對兩指針依次比較大小即可,注意對於空鏈表的處理 Code: #include<iostream> #incl

原创 LeetCode-13. 羅馬數字轉整數

地址:https://leetcode-cn.com/problems/roman-to-integer/ 思路:用unordered_map存下轉換情況,對於4和9的判斷,則看s[i+1]的值是否大於s[i]的值即可 Code: #

原创 LeetCode-18. 四數之和

地址:https://leetcode-cn.com/problems/4sum/ 思路:通過遍歷中間兩個數,再通過兩指針從數組兩端開始搜索判斷,同時注意對重複元素的判斷 Code: #include<iostream> #inclu

原创 LeetCode-25. K 個一組翻轉鏈表

地址:https://leetcode-cn.com/problems/reverse-nodes-in-k-group/ 思路:在翻轉時,保存連續的三個節點進行翻轉,以及注意翻轉區間和兩端的連接 Code: #include<ios

原创 LeetCode-14. 最長公共前綴

地址:https://leetcode-cn.com/problems/longest-common-prefix/ 思路:遍歷判斷即可 Code: #include<iostream> #include<algorithm> #in

原创 LeetCode-20. 有效的括號

地址:https://leetcode-cn.com/problems/valid-parentheses/ 思路:利用棧stack處理 Code: #include<iostream> #include<algorithm> #in

原创 LeetCode-23.合併K個排序鏈表

地址:https://leetcode-cn.com/problems/merge-k-sorted-lists/ 思路:一、每次比較k個鏈表的大小,在取最小的 二、利用優先隊列可優化每次k個鏈表的比較 Code: #include<

原创 LeetCode-16. 最接近的三數之和

地址:https://leetcode-cn.com/problems/3sum-closest/ 思路:一:先排序,再遍歷前二個數,在通過二分查找第三個數 二:先排序,再遍歷中間數,利用兩指針從數組兩端開始掃描 Code: #inc

原创 LeetCode-30.串聯所有單詞的子串

地址:https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/ 思路:用無序map保留words,遍歷字符串s,同時按照words中單詞的長度