259. 关闭分部的可行集合数目
难度:Hard 标签:位运算;图论;Floyd算法 链接: https://leetcode.cn/problems/number-of-possible-sets-of-closing-branches/ ...
难度:Hard 标签:位运算;图论;Floyd算法 链接: https://leetcode.cn/problems/number-of-possible-sets-of-closing-branches/ ...
难度:Hard 标签:哈希表;滑动窗口;字符串 链接: https://leetcode.cn/problems/minimum-window-substring/description/ ...
难度:Hard 标签:哈希表、字符串、滑动窗口 链接:https://leetcode.cn/problems/substring-with-concatenation-of-all-words/description/ ...
上一篇文章:股票问题与状态机dp 本篇文章涉及题目如下: 123. 买卖股票的最佳时机 III 188. 买卖股票的最佳时机 IV 309. 买卖股票的最佳时机含冷冻期 ...
本篇文章思路来源于 @bilibili/灵茶山艾府 题目描述:https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii 相对于买卖股票的最佳时机I,该问题可以多次买入和卖出股票以获取最大利益 ...
https://leetcode.cn/problems/palindrome-linked-list/ (1)将链表转化为数组进行比较 比较呆板的做法,空间复杂度为O(n)。 class Solution { public: bool isPalindrome(ListNode* head) { vector<int> arr; ListNode* p = head; while (p) { arr.push_back(p->val); p = p->next; } int n = arr.size(); for (int i = 0, j = n - 1; i < j; i++, j--) { if (arr[i] != arr[j]) return false; } return true; } }; (2)递归 链表也具有递归性质,二叉树也不过是链表的衍生。 利用后序遍历的思想: 先保存头结点(left,全局变量),然后递归至最后(最深)的结点(right),然后比较left和right的值;如果相等,由递归栈返回上一层(也即right向左走),再操作left向右走,这样就实现了left和right的双向奔赴。 class Solution { private: ListNode* left_ = nullptr; bool Traverse(ListNode* right) { if (!...