- 博客(127)
- 资源 (1)
- 收藏
- 关注
原创 KMP算法
KMP算法:前缀函数:对于长度为m的字符串s,前缀函数为π(i)(0<=i<m)表示s的子串s[0:i]的最长的相等的真前缀和真后缀的长度。特别地,如果不存在符合条件的前后缀,那么π(i)=0.真前缀,真后缀:不等于自身的前后缀。aabaaab: 0,1,0,1,2,2,3a ∅ ∅ 0aa a a 1aab a,aa ab,b 0aaba a,aa,aab a,ba,aba 1aabaa a,aa
2021-08-04 11:19:30
220
原创 leetcode1006:笨阶乘
class Solution {public: int myclumsy(int n,char op,long long int now1,long long int now2){ if(n==0) return now1-now2; if(op=='*'){ return myclumsy(n-1,'/',now1,now2*n); } else if(op=='/'){ return
2021-04-01 08:43:13
113
原创 leetcode173_3-28每日题:二叉搜索树迭代器
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *
2021-03-28 13:50:41
140
原创 leetcode83:删除排序链表中的重复元素
/** * Definition for singly-linked list. * 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), next(next)
2021-03-26 09:29:20
71
原创 leetcode82:删除排序链表中的重复元素II
/** * Definition for singly-linked list. * 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), next(next)
2021-03-25 23:20:56
66
原创 leetcode456_3-24每日题:132模式
class Solution {public: bool find132(vector<int>& nums,int start,int end){ if(end-start+1<3) return false; int max = nums[start]; int maxn = start; for(int i=start+1;i<=end;i++){ maxn = nums[
2021-03-24 13:13:57
85
原创 leetcode341_3-23每日题:扁平化嵌套列表迭代器
/** * // This is the interface that allows for creating nested lists. * // You should not implement it, or speculate about its implementation * class NestedInteger { * public: * // Return true if this NestedInteger holds a single integer, rather
2021-03-23 22:31:21
77
原创 leetcode191:位1的个数
class Solution {public: int hammingWeight(uint32_t n) { int res = 0; while(n!=0){ if(n&1==1) res+=1; n>>=1; } return res; }};
2021-03-22 10:09:24
63
原创 leetcode150:逆波兰表达式求值
class Solution {public: int evalRPN(vector<string>& tokens) { stack<int> num; for(int i=0;i<tokens.size();i++){ if(tokens[i]!="+"&&tokens[i]!="-"&&tokens[i]!="*"&&tokens[i]!="/"){
2021-03-20 16:09:27
73
原创 leetcode1603_3-19每日题:设计停车系统
class ParkingSystem {public: int big_park; int med_park; int sma_park; ParkingSystem(int big, int medium, int small):big_park(big),med_park(medium),sma_park(small) { } bool addCar(int carType) { switch(carType){
2021-03-19 10:33:58
89
原创 leetcode92_3-18每日题:反转链表II
/** * Definition for singly-linked list. * 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), next(next)
2021-03-18 10:14:53
80
原创 leetcode115_3-17每日题:不同子序列
class Solution {public: int numDistinct(string s, string t) { int answer = 0; map<char,int> m; for(int i=0;i<t.length();i++) m[t[i]] += 1; string s1; for(int i=0;i<s.length();i++){ if(m[s
2021-03-17 10:46:38
72
原创 Solidity
solidity语法接近于JavaScript,是一种面向对象的语言。但作为一种真正意义上运行在网络上的去中心化合约,它又有许多不同:以太坊底层基于账户,而不是UTXO。所以增加了一个特殊的address的数据类型用于定位用户和合约账户。语言内嵌框架支持支付。提供了payable等关键字,可以在语言层面直接支持支付。使用区块链进行数据存储。数据的每一个状态都可以永久存储,所以在使用时需要确定变量使用内存,还是区块链存储。运行环境是在去中心化的网络上,所以需要强调合约或函数执行的调用的方式。不同的异
2021-03-16 10:18:17
498
原创 leetcode76:最小覆盖子串
class Solution {public: string minWindow(string s, string t) { map<char,int> m; string s1 = s; for(int i=0;i<t.length();i++){ m[t[i]] += 1; } for(int i=0;i<s.length();i++){ if
2021-03-15 15:36:08
77
原创 leetcode75:颜色分类
class Solution {public: void sortColors(vector<int>& nums) { sort(nums.begin(),nums.end()); }};
2021-03-15 11:07:51
82
原创 leetcode706_3-14每日题:设计哈希映射
class MyHashMap {public: /** Initialize your data structure here. */ int *k[1000001]={nullptr}; stack<int> s; MyHashMap() { } /** value will always be non-negative. */ void put(int key, int value) { s.push(va
2021-03-14 14:36:03
68
原创 leetcode331_3-12每日题:验证二叉树的前序序列化
class Solution {public: bool isValidSerialization(string preorder) { if(preorder == "#") return true; stack<int> s; map<int,int> m; for(int i=0;i<preorder.length();i++){ if(preorder[i]==' ') c
2021-03-12 10:31:29
87
原创 以太坊虚拟机EVM
简介以太坊虚拟机EVM是智能合约的运行环境作为区块验证协议的一部分,参与网络的每个节点都会运行EVM。他们会检查正在验证的块中列出的交易,并运行由EVM中交易触发的带代码EVM不仅是沙盒封装的,而且是完全隔离的,也就是说在EVM中运行的代码时无法访问网络、文件系统和其他进程的,甚至智能合约之间的访问也是受限的。合约以字节码的格式存在于区块链上。合约通常以高级语言(solidity)编写,通过EVM编译器编译为字节码,最终通过客户端上载部署到区块链网络中。EVM和账户以太坊有两类账户:外部账户和
2021-03-11 17:47:46
270
原创 leetcode74:搜索二维数组
class Solution {public: bool searchMatrix(vector<vector<int>>& matrix, int target) { int left = 0, right = matrix.size()-1; while(left<right){ int mid = (left+right)/2; if(matrix[mid][0]>ta
2021-03-11 15:08:51
98
原创 leetcode227:基本计算器II
class Solution {public: int calculate(string s) { stack<int> num; stack<char> op; stack<int> n_num; queue<char> n_op; for(int i=0;i<s.length();i++){ if(s[i]==' ') continue;
2021-03-11 14:44:57
77
原创 JSON-RPC
以太坊客户端提供API和一组远程调用(RPC)命令,这些命令被编码为JSON。这被称为JSON-RPC API.本质上,JSON-RPC API就是一个接口,允许我们编写的程序使用以太坊网络和链上数据。RPC接口端口通常为8545,作为HTTP服务。出于安全原因,仅限于接受来自localhost的连接。要访问JSON-RPC API,可以使用编程语言编写的专用库,例如javaScript的web3.js。或者手动构建HTTP请求,如:$ curl -X POST -H "Content-Type:a
2021-03-10 19:36:33
393
原创 Geth Console
开启:geth --datadir . --networkid 15 console常用命令:eth:主要包含对区块链进行访问和交互相关的方法net:主要包含查看p2p网络状态的方法admin:主要包含与管理节点相关的方法miner:主要包含挖矿相关的一些方法personal:包含账户管理的方法txpool:包含查看交易内存池的方法web3:包含以上所有对象,还包含一些通用方法例子:eth.accounts 查看账户eth.getBalance(“账户哈希”) 查看账户余额eth.
2021-03-10 19:10:32
206
原创 leetcode224_3-10每日题:基本计算器
class Solution {public: int calculate(string s) { stack<char> op; stack<int> num; for(int i=0;i<s.length();i++){ if(s[i]=='(') op.push(s[i]); else if(s[i]==' ') continue; else
2021-03-10 12:49:40
65
原创 leetcode73:矩阵置零
class Solution {public: void setZeroes(vector<vector<int>>& matrix) { map<pair<int,int>,int> m; for(int i=0;i<matrix.size();i++){ for(int j=0;j<matrix[0].size();j++){ if(mat
2021-03-09 22:11:24
65
原创 leetcode72:编辑距离
class Solution {public: int minDistance(string word1, string word2) { int dp[500][500]; int m = word1.length(); int n = word2.length(); if(m==0||n==0) return max(m,n); if(word1[0]==word2[0]) dp[0][0] = 0;
2021-03-09 21:37:23
71
原创 leetcode71:简化路径
class Solution {public: string simplifyPath(string path) { string res="/"; for(int i=0;i<path.length();i++){ if(path[i]=='/'&&res[res.length()-1]=='/') continue; else if((i-1<0||(i-1>=0&&
2021-03-09 20:45:09
71
原创 leetcode69:x的平方根
class Solution {public: int mySqrt(int x) { if(x == 0) return 0; if(x == 1) return 1; int left = 0,right = x/2+1; while(left<right){ int mid = (left+right)/2; if(mid > x/mid) right = mid-1;
2021-03-09 19:55:10
51
原创 leetcode68:文本左右对齐
class Solution {public: vector<string> fullJustify(vector<string>& words, int maxWidth) { vector<vector<string> > answer; vector<string> now; int nowwidth=0; for(int i=0;i<words.size
2021-03-09 19:45:54
80
原创 leetcode67:二进制求和
class Solution {public: string addBinary(string a, string b) { int n_a = a.length(); int n_b = b.length(); int num_a = max(n_a,n_b); int num_b = min(n_a,n_b); string res; reverse(a.begin(),a.end());
2021-03-09 19:09:38
75
原创 leetcode1047_3-9每日题:删除字符串中所有相邻重复项
class Solution {public: string removeDuplicates(string S) { for(int i=1;i<S.length();i++){ if(i-1>=0&&S[i]==S[i-1]) { S.erase(i-1,2); i-=2; } } return S;
2021-03-09 18:10:36
124
原创 leetcode66:加一
class Solution {public: vector<int> plusOne(vector<int>& digits) { int res=0; for(int i = digits.size()-1;i>=0;i--){ if(i==digits.size()-1)digits[i] +=1; else digits[i]+=res; res = 0; if(digi
2021-03-08 17:16:59
62
原创 leetcode65:有效数字
class Solution {public: bool isNumber(string s) { bool flage=false; int pose=-1; bool flagd=false; for(int i=0;i<s.length();i++){ if((i==0&&(s[i]=='+'||s[i]=='-'))|| (i==pose+1&&am
2021-03-08 16:24:40
104
原创 leetcode132_3-8每日题:分割回文串II
class Solution {public: bool huiwen(string s){ for(int i=0;i<s.length();i++){ if(s[i]!=s[s.length()-1-i]) return false; } return true; } int minCut(string s) { int n = s.length(); int dp[
2021-03-08 13:12:33
75
原创 leetcode131_3-7每日题:分割回文串
class Solution {public: bool huiwen(string s){ for(int i=0;i<s.length();i++){ if(s[i]!=s[s.length()-1-i]) return false; } return true; } vector<vector<string> > answer; void func(string s
2021-03-07 13:06:34
81
原创 leetcode503_3-6每日题:下一个更大元素II
class Solution {public: vector<int> nextGreaterElements(vector<int>& nums) { stack<pair<int,int> > s1; vector<int> answer; map<int,int> m; bool flag = true; for(int i=0;m.
2021-03-06 22:33:09
72
原创 leetcode70:爬楼梯
class Solution {public: int climbStairs(int n) { if(n==0) return 0; if(n==1) return 1; int dp[n]; dp[0] = 1; dp[1] = 2; for(int i=2;i<n;i++){ dp[i] = dp[i-1]+dp[i-2]; } ret
2021-03-06 22:31:46
82
原创 leetcode232_3-5每日题:用栈实现队列
class MyQueue {public: stack<int> s1,s2; /** Initialize your data structure here. */ MyQueue() { } /** Push element x to the back of queue. */ void push(int x) { s1.push(x); } /** Removes the el
2021-03-05 10:40:19
116
1
原创 leetcode354_3-4每日题:俄罗斯套娃信封问题
class Solution {public: static bool compare(vector<int> a,vector<int> b){ if(a[0]<b[0]) return true; else if(a[0]>b[0]) return false; else{ if(a[1]<b[1]) return true; else return fal
2021-03-04 12:07:00
132
1
原创 leetcode338_3-3每日题:比特位计数
class Solution {public: vector<int> countBits(int num) { vector<int> res; res.push_back(0); if(num >= 1){ res.push_back(1); } int n = num; while(num!=0){ num>&g
2021-03-03 19:07:23
73
1
原创 leetcode203:移除链表元素
/** * Definition for singly-linked list. * 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), next(next)
2021-03-03 00:15:51
69
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人