摘要: 加油站 class Solution { public: int canCompleteCircuit(vector<int>& gas, vector<int>& cost) { int n = gas.size(); int ans = 0; int min_s = 0, s = 0; for( 阅读全文
posted @ 2025-02-14 21:37 skyler886 阅读(7) 评论(0) 推荐(0)
摘要: 买卖股票的最佳时机 II class Solution { public: int maxProfit(vector<int>& prices) { int answer = 0; for(int i = 1 ; i < prices.size(); i++) { if(prices[i] - pr 阅读全文
posted @ 2025-02-13 20:45 skyler886 阅读(11) 评论(0) 推荐(0)
摘要: 分发饼干 class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int m = g.length, n = s.length; int count = 0 阅读全文
posted @ 2025-02-13 19:39 skyler886 阅读(16) 评论(0) 推荐(0)
摘要: 非递减子序列 class Solution { public: vector<vector<int>> result; vector<int> path; void backTracking(vector<int>& nums, int startIndex) { if(path.size() > 阅读全文
posted @ 2025-02-12 16:19 skyler886 阅读(11) 评论(0) 推荐(0)
摘要: 93.复原IP地址 class Solution { public: vector<string> result; bool isValid(string & s, int start, int end) { if(start > end) return false; if(s[start] == 阅读全文
posted @ 2025-02-12 15:15 skyler886 阅读(9) 评论(0) 推荐(0)
摘要: 组合总和 class Solution { public: vector<vector<int>> result; vector<int> temp; void backTracking(int startIndex, int& Sum, vector<int>& candidates, int t 阅读全文
posted @ 2025-02-11 21:44 skyler886 阅读(11) 评论(0) 推荐(0)
摘要: 回溯算法理论基础 题目分类:组合 分割 子集 排列 棋盘 其他 模板 ` void backtracking(参数) { if (终止条件) { 存放结果; return; } for (选择:本层集合中元素(树中节点孩子的数量就是集合的大小)) { 处理节点; backtracking(路径,选择 阅读全文
posted @ 2025-02-08 16:25 skyler886 阅读(8) 评论(0) 推荐(0)
摘要: 209. 长度最小的子数组 class Solution { public: int minSubArrayLen(int target, vector<int>& nums) { int n = nums.size(); int left = 0, sum = 0; int min_len = I 阅读全文
posted @ 2025-01-09 22:52 skyler886 阅读(21) 评论(0) 推荐(0)
摘要: 704. 二分查找 左闭右闭 class Solution { public: int search(vector<int>& nums, int target) { int left = 0; int right = nums.size() - 1; // 定义target在左闭右闭的区间里,[l 阅读全文
posted @ 2025-01-08 21:16 skyler886 阅读(27) 评论(0) 推荐(0)