自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(63)
  • 资源 (2)
  • 收藏
  • 关注

原创 Python 固定时间调用装饰器

import timedef FixUpdate(deltatime=0.2): if 'fixUpdate' not in globals(): globals()['fixUpdate'] = {} def warp(func): def wrapper(*args,**kwargs): key = func.__name__ if key not in globals()['fixUpdate']:.

2020-06-03 14:41:19 256

原创 C# 动态调用类方法(反射)

using System;namespace DefaultNamespace{ public class A { public void greet() { Console.WriteLine("greeting from A"); } } public class B { public void greet() { Conso.

2020-06-01 21:07:37 1616 1

原创 LeetCode - 1115.交替打印FooBar(字节跳动面试题)

class FooBar {private: int n; mutex m1, m2;public: FooBar(int n) { this->n = n; m2.lock(); } void foo(function<void()> printFoo) { for (i...

2019-10-15 16:00:28 315

原创 LeetCode - 45.跳跃游戏II (困难)

动态规划 + 特殊条件判断class Solution {public: int jump(vector<int>& nums) { if(nums.size()==0){ return -1; } vector<int> dp; dp.resize(nums.s...

2019-10-14 10:43:23 158

原创 LeetCode - 71.简化路径

python解之class Solution(object): def simplifyPath(self, path): path = path + '/' path_array = [i for i in path.split('/') if i!='' and i!='.'] i = 0 while(i<l...

2019-10-13 21:31:06 126

原创 LeetCode - 93.复原IP地址

暴力,效率还行。class Solution {public: vector<string> restoreIpAddresses(string s) { vector<string> ret; if(s.size()<4 || s.size()>12){ return ret; ...

2019-10-13 21:06:59 88

原创 LeetCode - 547.朋友圈

DFS解之。class Solution {public: int count = 0; int findCircleNum(vector<vector<int>>& M) { vector<int> visited; visited.resize(M.size()); f...

2019-10-13 19:47:06 110

原创 LeetCode - 236.二叉树的最近公共祖先

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */...

2019-10-13 19:30:12 133

原创 LeetCode - 148.链表排序

好像以前做过,归并排序的形式实现。用快慢指针找到链表的中点,使用归并排序的方法对左边的链表和 右边的链表分别递归执行排序。然后合并两个排序好的链表。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNod...

2019-10-13 15:23:15 168 1

原创 LeetCode - 10.正则表达式匹配

class Solution {public: bool isMatch(string s, string p) { return isMatchMeta(s,p,0,0); } bool isMatchMeta(string s, string p,int i,int j) { if(i>s.size() || j>p.si...

2019-10-10 11:47:08 94

原创 LeetCode - 60.第k个排列

https://leetcode-cn.com/problems/permutation-sequence/一共有n!个排列,可以进行排列的数字为[1,2,3,4,5,6,...n],通过观察可知,第0位置的数字​ ​​​​​​的排列等于 i*(n-1)!,即当= 0 时候,,当= 1时候, , ...依次类推。这里假定k的最小值为0(在程序中做了减法);cla...

2019-10-10 10:10:12 106

原创 LeetCode - 103.二叉树的锯齿形层次遍历

按层序遍历,遇到奇数层时,翻转输出即可。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(...

2019-10-10 09:58:49 103

原创 LeetCode - 226.翻转二叉树

class Solution {public: TreeNode* invertTree(TreeNode* root) { if(root){ TreeNode *t = root->left; root->left = root->right; root->righ...

2019-10-09 20:39:34 126

原创 LeetCode - 200.岛屿的数量

用DFS搜索 ,效果还可以class Solution {public: vector<vector<int>> visited; int count = 0; int numIslands(vector<vector<char>>& grid) { if(grid.size()==0){ ...

2019-10-09 20:02:16 126

原创 LeetCode - 56.合并区间

class Solution {public: vector<vector<int>> merge(vector<vector<int>>& intervals) { if(intervals.size()==0){ return intervals; } s...

2019-10-09 19:41:26 109

原创 LeetCode - 221.最大正方形

class Solution {public: int maximalSquare(vector<vector<char>>& matrix) { vector<vector<int>> r; int m = matrix.size(); if(m==0){ ...

2019-10-09 17:27:58 111

原创 LeetCode - 354.俄罗斯套娃信封问题 (困难)

思路:对信封进行排序,两次遍历,对以当然信封为最后一个信封的返回值进行缓存,对信封高度进行判断。时间复杂度 O(n^2),空间复杂度 O(n)。class Solution {public: int maxEnvelopes(vector<vector<int>>& envelopes) { sort(envelopes.begi...

2019-10-09 15:37:46 138

原创 LeetCode - 62.不同的路径

class Solution {public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int m = obstacleGrid.size(); int n = obstacleGrid[0].size(); ...

2019-10-09 00:03:26 107

原创 LeetCode - 50.Pow(x,n)

ok,用我们最擅长的递归来实现以下。其中空间复杂度为O(logn),时间负责度为O(logn),每次将 x^n 拆成 x^(n/2) * x^(n/2)来做。对负数分母很大时进行INTMAX上限处理。class Solution {public: double myPow(double x, int n){ return myPow(x,n,0); ...

2019-10-07 20:07:31 142

原创 LeetCode - 146.LRU缓存

写了一个多小时才写完,真心感觉自己有点菜。要好好加强练习了。(比较不熟不熟双向链表)使用map + 双向链表来实现,删除可以达到O(1),查询可以达到O(1)struct Node{ Node *next; Node *previous; int key; int val; Node(int key,int val){ this-&...

2019-10-07 19:13:10 105

原创 LeetCode - 322.零钱的兑换 (两种方法、动态规划、递归)

第一种方法:使用缓存+递归算法.(运度超越5%,内存超5%)可以说是比较慢了class Solution {public: int **cache; int coinChange(vector<int>& coins, int amount) { const int n = coins.size(); cache = ...

2019-10-07 11:43:55 470

原创 LeetCode - 102.二叉树的层次遍历

给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。例如:给定二叉树:[3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其层次遍历结果:[ [3], [9,20], [15,7]]来源:力扣(LeetCode)链接:https://leetcode-cn...

2019-10-07 10:37:27 71

原创 LeetCode - 5.最长回文字串(中心扩散法)

有两种情况,第一种是中心是有数字,即最长回文的长度为奇数,一种是中心不是数字,即最长回文的长度为偶数。使用两个循环即可。class Solution {public: string longestPalindrome(string s) { const int n = s.size(); if(n==0){ return ""...

2019-10-07 10:25:56 142

原创 LeetCode - 46.全排列

回溯法,对应资源对应位置应该要还原。class Solution {public: vector<vector<int>> r; vector<vector<int>> permute(vector<int>& nums) { vector<int> res; p...

2019-10-06 21:05:39 63

原创 LeetCode -135.分发糖果

和雨水的那道题目有点类似,左边右边遍历一下保证符合题目条件即可。class Solution {public: int candy(vector<int>& ratings) { vector<int> candy; const int n = ratings.size(); candy.resize(...

2019-10-06 20:35:22 135

原创 LeetCode - 17.电话号码的字母组合

class Solution {public: vector<string> M= {"","*","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; vector<string> letterCombinations(string digits) { vector<stri...

2019-10-06 20:23:31 537

原创 LeetCode - 58.最后一个单词的长度

class Solution {public: int lengthOfLastWord(string s) { int ret = 0; // int mast = 0; int i = s.size() - 1; while(i>=0 && s[i]==' '){ i...

2019-10-06 15:31:47 62

原创 LeetCode - 67.二进制求和

给定两个二进制字符串,返回他们的和(用二进制表示)。输入为非空字符串且只包含数字1和0。示例1:输入: a = "11", b = "1"输出: "100"示例2:输入: a = "1010", b = "1011"输出: "10101"来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/add-binary...

2019-10-06 15:27:30 91

原创 LeetCode - 38.报数

class Solution {public: string countAndSay(int n) { if(n==1){ return "1"; } string s = countAndSay(n-1); string ret; char ...

2019-10-06 15:16:18 102

原创 LeetCode - 55.跳跃游戏

给定一个非负整数数组,你最初位于数组的第一个位置。数组中的每个元素代表你在该位置可以跳跃的最大长度。判断你是否能够到达最后一个位置。示例1:输入: [2,3,1,1,4]输出: true解释: 从位置 0 到 1 跳 1 步, 然后跳 3 步到达最后一个位置。示例2:输入: [3,2,1,0,4]输出: false解释: 无论怎样,你总会到达索引为 3 的位置。但...

2019-10-06 13:59:25 108

原创 LeetCode - 42.接雨水 (困难)

给定n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。感谢 Marcos 贡献此图。示例:输入: [0,1,0,2,1,0,1,3,2,1,2,1]输出: 6来源:力扣(LeetCode)链接:...

2019-10-06 13:49:05 165

原创 LeetCode - 36.有效的数独

判断一个9x9 的数独是否有效。只需要根据以下规则,验证已经填入的数字是否有效即可。数字1-9在每一行只能出现一次。数字1-9在每一列只能出现一次。数字1-9在每一个以粗实线分隔的3x3宫内只能出现一次。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/valid-sudoku著作权归领扣网络所有。商业转载请联系...

2019-10-06 13:35:39 141

原创 LeetCode - 丑数II

编写一个程序,找出第 n 个丑数。丑数就是只包含质因数2, 3, 5 的正整数。示例:输入: n = 10输出: 12解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。说明:1是丑数。n不超过1690。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/ugly-...

2019-10-06 13:23:02 84

原创 LeetCode - 101. 对称二叉树(两个版本)

1.简单递归版,翻转 + 判断两个树是否相等。class Solution {public: bool isSymmetric(TreeNode* root) { if(!root){ return true; } flip(root->right); return equal(root-...

2019-10-05 20:15:18 84

原创 LeetCode - 94.二叉树的中序遍历(非递归版本)

https://leetcode-cn.com/problems/binary-tree-inorder-traversal/submissions/OK,模拟一下递归的过程,使用两个stack写一下。class Solution {public: vector<int> inorderTraversal(TreeNode* root) { vect...

2019-10-05 19:51:24 127

原创 LeetCode - 233 数字1的个数(困难)

递归 求解,将数字转换为数组,deb表示当前是否允许0-9。AC100%class Solution {public: int countDigitOne(int n) { vector<int> r; do{ r.insert(r.begin(),n%10); n/=10; ...

2019-10-05 17:54:59 97

原创 LeetCode - 字节跳动模拟面试 - 螺旋矩阵

给定一个包含mxn个元素的矩阵(m行,n列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。示例1:输入:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]输出: [1,2,3,6,9,8,7,4,5]示例2:输入:[ [1, 2, 3, 4], [5, 6, 7, 8], [9,10,11,12]]...

2019-10-05 15:29:09 411

原创 LeetCode - 19.删除链表的倒数第N个节点

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */int len(ListNode* head){ int c =...

2019-10-05 14:06:32 65

原创 LeetCode - K个一组翻转链表

使用头插法 + 递归解, AC/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */int len(ListNode *head)...

2019-10-04 23:38:41 82

原创 LeetCode - 回文数(不使用字符串)

class Solution {public: bool isPalindrome(int x) { if(x<0){ return false; } long x1 = x; long x2 = 0; do{ x2*=10; x...

2019-10-04 23:00:42 90

数字信号处理第三版 高西全

数字信号处理第三版 数字信号处理第三版 数字信号处理第三版

2018-04-08

Reinforcement Learning An Introduction

强化学习大作! 推荐阅读 [Second Edition] Reinforcement Learning An Introduction Draft

2018-04-08

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除