- 博客(10)
- 收藏
- 关注
原创 leetcode 53. 最大子序和
class Solution { public: int maxSubArray(vector<int>& nums) { if(nums.size() == 1){ return nums[0]; } int sum = 0; int ans = INT_MIN; ...
2020-01-27 11:59:14 323
原创 leetcode 303. 区域和检索 - 数组不可变
前缀和 class NumArray { public: vector<int> sum; NumArray(vector<int>& nums) { if(nums.size()>0){ sum.push_back(nums[0]); } for(int i=1;i<...
2020-01-27 11:51:35 235
原创 假期作业目录
(二选一) poj1636 Prison rearrangement(连通分量+背包) poj1088 滑雪(带有备忘的递归|拓扑排序) (二选一) poj2366 poj3233 (二选一) poj1753 Flip Game poj3714 Raid (二选一) poj3269 Building A New Barn(中位数) poj3579 Median(二分) 哈希(二选一) [M]380...
2020-01-27 11:21:57 1367 2
原创 leetcode 105. 从前序与中序遍历序列构造二叉树
递归, 在中序中找前序的第一个元素, 之后切割成两个相同子问题 class Solution { public: TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) { if(preorder.size()==0){ return n...
2020-01-27 11:19:49 273
原创 leetcode 589. N叉树的前序遍历
递归 class Solution { public: vector<int> ret; vector<int> preorder(Node* root) { findw(root); return ret; } void findw(Node*root){ if( root!= nullptr...
2020-01-27 10:44:07 186 1
原创 leetcode 307. 区域和检索 - 数组可修改 前缀和 | 线段树
前缀和 查询是O(1) 更新是O(n) class NumArray { public: vector<int> sum; vector<int> nums; NumArray(vector<int>& nums) { this->nums = nums; sum = vector<in...
2020-01-25 23:20:14 317
原创 leetcode 382. 链表随机节点
从头开始计数 第i个点选择的概率是1i\frac{1}{i}i1 只需要区[0,i-1]的随机数,如果,取到了0,就更新返回值,否则不更新 class Solution { public: /** @param head The linked list's head. Note that the head is guaranteed to be not null, so ...
2020-01-25 19:10:41 269
原创 leetcode 56. 合并区间
区间左端点进行排序 如果intervals小于等于一个元素直接返回 如果大于1个 按照左边点进行排序 从左至右依次合并 class Solution { public: static bool cmp(vector<int>&a,vector<int>&b){ return a[0] < b[0]; } bo...
2020-01-25 18:36:04 183
原创 EOJ Monthly 2020.1 A. 回文时间
https://acm.ecnu.edu.cn/contest/247/problem/A/ 因为是对称的,只考虑前七位 2020012 | 2100202 0123 45 6 2020 | 01 | 2 年 | 月 | 日 0位和2位的取值范围:{"0","1","2","3","4","5","6","7","8","9"} 1位和3位的取值范围: {"0","1","2","3...
2020-01-18 18:59:08 447
原创 POJ 2366 Sacrament of the sum 二分查找 哈希表
题干那么长,就是在两个数组里面分别找一个数,使得和为10000 法一:二分查找 法二:数组(哈希) 转载自 https://www.cnblogs.com/wwdf/p/5781351.html #include<cstdio> #include<cmath> #include<cstring> #include<queue> #include<...
2020-01-14 19:40:56 811 2
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人