每日一题
sunmaoxiang
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
二分上下取整
ok | no for i < j { mid := int(uint(i+j+1) >> 1) if !judge(mid) { j = mid - 1 } else { i = mid; } } no | ok for i < j { mid := int(uint(i+j) >> 1) if !judge(mid) { i = mid + 1; } else { j = mid; } }原创 2022-01-05 10:00:57 · 314 阅读 · 0 评论 -
[每日一题 day4] 42. 接雨水
思路就是用两个数组分别存一下左边最高的和右边最高的。 代码: int maxl[30005]; int maxr[30005]; class Solution { public: int trap(vector<int>& height) { int n = height.size(); memset(maxl, 0, sizeof(maxl)); memset(maxr, 0, sizeof(maxr)); int原创 2021-03-19 20:00:32 · 172 阅读 · 0 评论 -
[每日一题 day3] 92. 反转链表 II
https://leetcode-cn.com/problems/reverse-linked-list-ii/ 反转链表的中间一段。 struct ListNode { int val; ListNode *next; ListNode() : val(0), next(nullptr) {} ListNode(int x) : val(x), next(nullptr) {} ListNode(int x, ListNode *next) : val(x), ne原创 2021-03-18 11:51:32 · 145 阅读 · 0 评论 -
[每日一题 day2]115. 不同的子序列
https://leetcode-cn.com/problems/distinct-subsequences/ 思路: 动态规划思路 d[i][j] 代表 s[0,i-1]与t[0, j-1]中匹配最多的子序列个数 相当于原来问题的子问题 特殊情况是t为空匹配s[0, n-1]的结果都为1,然后进行状态转移递推 注意的当相等的情况分为进行匹配和不进行匹配两种情况分别对应状态d[i-1][j-1]与d[i-1][j] #include <iostream> #include <cstri原创 2021-03-17 10:33:02 · 166 阅读 · 0 评论 -
[ 每日一题day1 ] 200. 岛屿数量
题目链接:https://leetcode-cn.com/problems/number-of-islands/ 求联通块个数有几种方法, dfs方法: class Solution { private: int n, m; int dir[4][2] = { {0,1},{0,-1}, {1, 0}, {-1,0} }; public: // dfs void dfs(vector<vector<char>>& grid, int r, i原创 2021-03-15 16:08:58 · 184 阅读 · 0 评论
分享