自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(288)
  • 收藏
  • 关注

原创 SyntaxError: unexpected EOF while parsing

结果发现少打了一个反括号。。。

2021-03-22 17:22:09 219

原创 No version of NDK matched the requested version 21.0.6113669. Versions available locally: 21.3.65281

No version of NDK matched the requested version 21.0.6113669. Versions available locally: 21.3.65281471.在Android studio中,选择file->project structure。在弹出的窗口中选择SDK location,在Android NDK location选择路径2.但是可能无法选择路径,因此可以直接在项目的local.properties中添加ndk.dir=<.

2020-12-02 14:07:07 3520

原创 Ubuntu update报错sh: 1: /usr/lib/cnf-update-db: not found

原因是之前把python3的软连接改成了python在/usr/bin里sudo cp python python3就可以了

2020-11-10 16:23:45 6244 5

原创 [libtorch/C++]clone与copy

int main() { auto x = torch::zeros({2, 2}); auto y = x; auto m = x.clone(); auto n = torch::zeros_like(x); n.copy_(x); x[0][0] = 1; cout << y[0][0] << m[0][0] << n[0][0]; return 0;}输出1,0,0说明直接赋值是共享内存的。根据文档,clone会被记录到计

2020-09-07 20:00:15 948

原创 [libtorch/C++] reflection_pad2d

在pytorch1.6中,必须如下调用x =torch::reflection_pad2d(x,{1,1,1,1});

2020-09-07 19:51:44 342

原创 全错位排列/C++

f(n)=(n-1)(f(n-1)+f(n-2))f(0)=0f(1)=0f(2)=1int getvalue(int num){ if (num == 1) return 0; else if (num == 2) return 1; else{ int f1 = 0; int f2 = 1; for (int i = 3; i <= num; i++){ ...

2019-09-29 10:04:28 1396

原创 899. 有序队列/C++

string orderlyQueue(string S, int K) { if (K == 1) { int size = S.size(); string ans = S; S = S+S; for (int i = 0; i < size; ++i) { string tmp = S.substr(i,size); if(ans.co...

2019-09-17 14:40:15 607

原创 AcWing 197. 阶乘分解/C++(质数筛+快速幂)

我们发现N!中质数因子p的个数,就是1~N中每个数含有的质因数p个数。至少有一个质因子p的有⌊Np⌋\lfloor\frac{N}{p}\rfloor⌊pN​⌋(向下取整)个,而至少有两个质因子p数的有⌊Np2⌋\lfloor\frac{N}{p^2}\rfloor⌊p2N​⌋个。#include<iostream>#include<vector>using na...

2019-09-01 17:01:21 380

原创 不指定数组长度,输入一行数组

int main(){ vector<int> vec; int i = 0; do{ cin >> i; vec.push_back(i); }while(getchar() !='\n'); return 0;}getchar()可...

2019-08-29 20:06:47 1145

原创 二叉树:n0=n2+1

二叉树的度,按照有向图的说法,应该是出度,也就是这个点有几个孩子。按照度的多少可以分为0,1,2.度为0就是叶子节点,度为1就是只有一个孩子的节点,度为2就是有2个孩子的节点。先说结论:n0=n2+1n_0=n_2+1n0​=n2​+1证明:先考虑入度,也就是除根外,每个节点都有且只有一个父节点,即入度=n0+n1+n2−1入度=n_0+n_1+n_2-1入度=n0​+n1​+n2​−1。...

2019-08-17 11:25:02 4759

原创 282. 给表达式添加运算符/C++(超时)

class Solution {public: vector<string> addOperators(string num, int target) { vector<string> res; help(num,target,0,0,"",res); return res; } void...

2019-08-11 11:01:53 313

原创 944. 删列造序/C++

int minDeletionSize(vector<string>& A) { if(A.empty() || A[0]=="") return 0; vector<int> res; int m = A[0].size(), n = A.size(); for(int i=0;i<m;++i){ ...

2019-08-11 10:31:24 248

原创 665. 非递减数列/C++

如果nums[i]>nums[i+1],可以增大nums[i+1],也可以减小nums[i],依据是比较nums[i-1]与nums[i+1]的大小。bool checkPossibility(vector<int>& nums) { if(nums.size()<3) return true; int cnt = 0;...

2019-08-11 10:16:48 367

原创 92. 反转链表 II/C++

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* r...

2019-08-10 17:04:02 180

原创 18. 四数之和/C++

vector<vector<int>> fourSum(vector<int>& nums, int target) { vector<vector<int>> res; sort(nums.begin(), nums.end()); int size = nums.size(); for(i...

2019-08-10 11:09:19 315

原创 827. 最大人工岛/C++(深度优先遍历)

深度优先遍历2次第一次将各个岛分类,同一个岛上的格子使用同一种编号,并且得到每个岛屿的大小;第二次试着将所有海洋都填一遍,找出最大的结果。class Solution { vector<vector<int>> dir{{0,1},{0,-1},{1,0},{-1,0}};public: int largestIsland(vector<vector&l...

2019-08-10 10:12:16 373

原创 753. 破解保险箱/C++

以res的后n-1位为新字符串的前缀,再找一个j,组成n位的字符串。set保证不重复。并且j要从大往小的找,才能全部搜索到。class Solution {public: string crackSafe(int n, int k) { string res(n,'0'); unordered_set<string> set; ...

2019-08-05 21:08:54 730

原创 1106. 解析布尔表达式/C++

与波兰表达式类似,利用2个栈,一个存数字,一个存运算符。略有不同的是,四则运算都是双目运算符,每次计算都是弹出2个数字与1个运算符,结果再压入数字栈中。但是此题的运算符(或与)都是多目运算符,遇到)要一直弹出到(,用两个变量记录是否出现t或f,对于&,只要出现false结果就是false对于|,只要出现true结果就是true对于!,出现false结果就是trueclass ...

2019-08-05 16:39:29 2149

原创 572. 另一个树的子树/++

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

2019-08-05 16:02:20 229

原创 212. 单词搜索 II/++

class Solution { struct Node{ char c; bool finished; string word; Node* children[26]; Node(char ch) :c(ch), finished(false) { memset(children, 0, sizeo...

2019-08-05 15:42:42 300

原创 149. 直线上最多的点数/C++

class Solution { int gcd(int y,int x){ return x==0?y:gcd(x,y%x); }public: int maxPoints(vector<vector<int>>& points) { int n = points.size(); if(n...

2019-08-05 14:23:52 458

原创 295. 数据流的中位数/C++

利用最大堆和最小堆,始终保持两个堆的大小最多只相差1,如果大小相等,则中位数是两个堆根节点的平均数,否则就是较多的那个堆的根节点。当最大堆比较多,如果是大的数,则直接加入最小堆,如果是小的数,则将最大堆的根节点移到最小堆,令最小堆更多,将小的数加入最大堆反之同理class MedianFinder { priority_queue<double> maxHe...

2019-08-05 11:23:17 138

原创 315. 计算右侧小于当前元素的个数/C++

class Solution {public: struct TreeNode { int val; int count; TreeNode* left; TreeNode* right; TreeNode(int x) { val=x; ...

2019-08-05 10:26:50 194

原创 140. 单词拆分 II/C++

class Solution {public: vector<string> wordBreak(string s, vector<string>& wordDict) { unordered_set<string> set(wordDict.begin(), wordDict.end()); unorder...

2019-08-02 10:36:07 415

原创 1021. 删除最外层的括号/C++

string removeOuterParentheses(string S) { string res; stack<char> st; for(char c:S){ if(c==')') st.pop(); if(!st.empty()) res+=c; if(...

2019-08-01 20:35:35 275

原创 100. 相同的树/C++

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

2019-08-01 20:25:55 117

原创 58. 最后一个单词的长度/C++

int lengthOfLastWord(string s) { for(int i=s.size(); --i && s[i]==' '; s.pop_back()); int cnt = 0; for(int i=s.size()-1;i>=0;--i){ if(s[i]!=' ') ++cnt; ...

2019-08-01 11:16:19 153

原创 67. 二进制求和/C++

string addBinary(string a, string b) { int as=a.size(),bs=b.size(); int size = max(as,bs); string str(size+1,'0'); int k = size-1; for(int i=as-1,j=bs-1,k=size,n=0;i>=0||j...

2019-08-01 11:08:03 218

原创 110. 平衡二叉树/C++

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

2019-08-01 10:47:49 144

原创 24. 两两交换链表中的节点/C++

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* s...

2019-08-01 10:34:11 105

原创 218. 天际线问题/C++

扫描线vector<vector<int>> getSkyline(vector<vector<int>>& buildings) { multiset<pair<int,int>> set; vector<vector<int>> res; for(vec...

2019-08-01 10:19:13 520 1

原创 329. 矩阵中的最长递增路径/C++

记忆化深度优先搜索class Solution {public: vector<vector<int>> direction{{1,0},{-1,0},{0,1},{0,-1}}; int m,n; int longestIncreasingPath(vector<vector<int>>& matri...

2019-07-31 21:05:21 481

原创 1138. 字母板上的路径/C++

由于z的特殊位置,右和下要放在后面,以防止出界string alphabetBoardPath(string target) { int r=0,c=0; string res; for(char ch:target){ int row = (ch-'a')/5,col=(ch-'a')%5; while(c>col){ ...

2019-07-30 16:56:53 122

原创 1137. 第 N 个泰波那契数/C++

int tribonacci(int n) { if(n<0) return -1; else if(n==0) return 0; else if(n==1 || n==2) return 1; else{ int n0=0,n1=1,n2=1,n3; for(int i=3;...

2019-07-30 16:42:36 266

原创 166. 分数到小数/C++

string fractionToDecimal(int numerator, int denominator) { if(numerator==0) return "0"; string res; //添加负号 if(numerator>0 ^ denominator>0) res+="-"; ...

2019-07-30 15:11:00 303

原创 138. 复制带随机指针的链表/C++

递归class Solution {public: unordered_map<Node*,Node*> visited; Node* copyRandomList(Node* head) { if(!head) return nullptr; if(visited.find(head)!=visited.end(...

2019-07-30 09:17:11 200

原创 127. 单词接龙/C++

int ladderLength(string beginWord, string endWord, vector<string>& wordList) { int L = beginWord.size(); unordered_map<string,vector<string>> map; for(string st...

2019-07-29 20:54:24 632

原创 44. 通配符匹配/C++

动态规划dp[i][j]表示s的前i个字符与p的前j个字符是否匹配。bool isMatch(string s, string p) { size_t m = s.size(), n = p.size(); vector<vector<bool>> dp(m + 1, vector<bool>(n + 1, false)); dp[0][0] =...

2019-07-29 11:13:01 782

原创 12. 整数转罗马数字/C++

string intToRoman(int num) { vector<int> val = { 1000,900,500,400,100,90,50,40,10,9,5,4,1 }; vector<string> dic = { "M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I" }; ...

2019-07-29 10:02:12 296

原创 6. Z 字形变换/C++

第一行:行0中的字符位于索引2*(numRows-1)处;最后一行:行numRows−1中的字符位于索引2(numRows−1)k+numRows−1处;内部的行:行i中的字符位于索引2(numRows−1)k-i以及2(numRows−1)k+numRows+1处;将每个向下以及向右上的部分看作一个循环。对于示例2,循环1:LEET CO;循环2:DEIS HI;循环3:RINGst...

2019-07-29 09:07:50 236

空空如也

空空如也

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

TA关注的人

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