![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
邢海博
这个作者很懒,什么都没留下…
展开
-
<leetcode>10.正则表达式匹配
代码:class Solution {public: bool isMatch(string s, string p) { vector<vector<bool>> dp (s.size()+1, vector<bool>(p.size()+1, false)); dp[0][0] = true; f...原创 2020-03-07 00:12:09 · 77 阅读 · 0 评论 -
<leetcode>328.奇偶链表
思路1:1.链表拆分&合并2.每次同时处理奇偶节点,需要判断边界问题,比较复杂3.末尾处要设置成指向空/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(...原创 2020-03-05 09:43:09 · 109 阅读 · 1 评论 -
<leetcode>143.重排链表(递归)
利用递归来解决该问题,一层一层处理代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {pu...原创 2020-03-04 23:15:47 · 177 阅读 · 0 评论 -
<leetcode>24.两两交换链表中的节点
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* s...原创 2020-03-04 16:44:21 · 62 阅读 · 0 评论 -
<leetcode>21.合并两个有序链表
无比丑陋的代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li...原创 2020-03-04 12:47:13 · 73 阅读 · 0 评论 -
<leetcode>2. 两数相加(链表)
原方法:class Solution {public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { auto l3 = new ListNode(-1); auto res = l3; int jinwei = 0; while(l1 && l...原创 2020-03-04 11:47:33 · 64 阅读 · 0 评论 -
<leetcode>234.反转链表
比较简洁高效的程序:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: L...原创 2020-03-04 10:48:57 · 145 阅读 · 0 评论 -
<leetcode>234.回文链表
代码:class Solution {public: bool isPalindrome(ListNode* head) { if(!head || !head->next) return true; ListNode* slow = head; ListNode* fast = head; while(fast ...原创 2020-03-03 20:04:32 · 78 阅读 · 0 评论 -
<leetcode>15.三数之和
解答思路如下:代码如下:class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> ans; if(nums.size() < 3)//如果长度不足...原创 2020-02-25 19:07:43 · 66 阅读 · 0 评论 -
<leetcode>264.丑数Ⅱ
求解第n个丑数a[n],前面肯定存在三个最小的下标i,j,k属于(1,2,…,n-1)使得a[i]*2,a[j]*3,a[k]*5刚好大于a[n-1],然后选取三者中最小的即为a[n]下面看看这三个下标,它满足两个条件:1.乘以对应的因子一定大于a[n-1];2.满足1的同时又是最小的。从头开始,a[1]=1,毫无疑问,i=j=k=1。显然,这时肯定选i,a[2]=2。现在2已经在数组a里了...转载 2020-02-25 11:19:34 · 67 阅读 · 0 评论 -
<leetcode>983.最低票价
class Solution {public: int mincostTickets(vector<int>& days, vector<int>& costs) { vector<int> dp(366, 0); int k = 0;//访问days[] int tar;储存一年中最后...原创 2020-02-24 23:13:20 · 96 阅读 · 0 评论 -
<leetcode>一些常用模板
// 快速排序算法模板void quick_sort(int q[], int l, int r){ if (l >= r) return; int i = l - 1, j = r + 1, x = q[l]; while (i < j) { do i ++ ; while (q[i] < x); do j ...转载 2020-02-24 18:00:44 · 187 阅读 · 0 评论 -
<leetcode>216.组合总数3
题目描述: 由于循环层数是不确定的,考虑递归的方法来做,每一层都更新余下数字和、余下数字个数、起始数字,都要保留两个储存结果的数组。递归中利用回溯的思想,每次push_back后必须跟随pop_back,如果其他数字发生改变,也需要在递归调用后改回来。由于递归的终点是输出一个结果,不需要判断真假,函数返回值void即可。代码class Solution {public: ...原创 2020-02-22 14:18:41 · 99 阅读 · 0 评论