问题分类
weixin_44578662
这个作者很懒,什么都没留下…
展开
-
Pattern: DP,最长上升子序列(LIS)、最长公共子序列(LCS)、最长公共子串、最长回文子序列
最长上升子序列 关键在于dp数组的含义:dp[i] 表示以 nums[i] 这个数结尾的最长上升子序列的长度。 class Solution { public: int lengthOfLIS(vector<int>& nums) { //思路:dp数组用来存放以第i个数字结尾的最长上升子序列长度 int res=0; vector<int> dp(nums.size(),1);//注意此处初始化为1,子原创 2020-07-01 13:37:29 · 176 阅读 · 0 评论 -
Pattern: Sliding Window,滑动窗口类型
滑动窗口类型无重复字符的最长子串水果成篮 无重复字符的最长子串 class Solution { public: int lengthOfLongestSubstring(string s) { int start=0,end=0,length,max_length=0; while(end!=s.size()) { //for循环检查s[end]在[start,end)区间中是否出现过 fo原创 2020-06-11 12:34:57 · 166 阅读 · 0 评论 -
Pattern: In-place Reversal of a LinkedList,反转链表
反转链表反转链表Ⅰ反转链表 IIK 个一组翻转链表 反转链表Ⅰ /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* reverseList(ListNode* hea原创 2020-06-09 09:56:52 · 81 阅读 · 0 评论