![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
力扣
yuyijie_1995
半路出家菜鸡程序员一枚
展开
-
背包问题详解
01背包为何压缩后要逆序 如下图所示 为01背包压缩的模式 for (int i = 1; i <= n; i++) for (int j = V; j >= 0; j--) f[j] = max(f[j], f[j - w[i]] + v[i]); 这里用别的博客的一张图的例子,图中是二维的情况,比较简单不做赘述 我这边手绘了一个表格来表示1维的情况 ...原创 2021-02-13 22:41:45 · 195 阅读 · 0 评论 -
力扣12 13
#include<iostream> #include<vector> #include<string> #include<map> using namespace std; class Solution { public: string intToRoman(int num) { int values[] = { 1000, 900, 5...原创 2020-03-19 22:12:06 · 105 阅读 · 0 评论 -
力扣11
双指针法 #include<iostream> #include<vector> #include "pch.h" using namespace std; class Solution { public: int maxArea(vector<int>& height) { int length = height.size(); int ...原创 2020-03-15 23:54:25 · 139 阅读 · 0 评论 -
力扣10
分情况讨论: 这里我们不去讨论能不能匹配上,重点关注当前字符后面有*没有*的回溯情况,用一个当前字符是否匹配上作为回溯标记,用index是否等于待匹配字符长度作为回溯终止条件。 后面有星号有两种可能,一是要取到当前字符但是因为待匹配字符后面有星号所以待匹配字符的index并不后移继续进行匹配因为它能匹配1个或多个相同字符,二是跳过当前字符和后面的星号 #include "pch.h" #incl...原创 2020-03-12 23:29:14 · 188 阅读 · 0 评论 -
力扣9
#include "pch.h" #include<vector> #include<string> #include<iostream> using namespace std; #include<algorithm> class Solution { public: bool isPalindrome(int x) { if (x &...原创 2020-03-11 09:49:31 · 85 阅读 · 0 评论 -
力扣8
// leetcode.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include "pch.h" #include<vector> #include<string> #include<iostream> using n...原创 2020-03-11 09:36:12 · 132 阅读 · 0 评论 -
力扣7
思路就是把一个数字的最后一位提取放到第一位,知道用尽该数的每一位数 利用%和/符号 #include "pch.h" #include<vector> #include<string> #include<iostream> using namespace std; class Solution { public: int reverse(int x) {...原创 2020-03-08 13:57:55 · 117 阅读 · 0 评论 -
力扣6
class Solution { public: string convert(string s,int numRows) { if (numRows == 1) { return s; } int sSize = s.size(); int storeSize = min(sSize, numRows); vector<string> st...原创 2020-03-07 11:02:42 · 152 阅读 · 0 评论 -
力扣2 两数相加
class Solution { public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { int a = 0, b = 0; int carryBit = 0; //进位变量 ListNode *result = new ListNode(0); //增添头结点,方便操作 ListNode *current...原创 2020-03-06 16:41:43 · 207 阅读 · 0 评论 -
力扣5 最长回文子串
// leetcode.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include "pch.h" #include<vector> #include<string> #include<iostream> using nam...原创 2020-03-06 16:32:27 · 72 阅读 · 0 评论