随笔分类 -  leetcode

摘要:class Solution { public: int longestPalindrome(string s) { int re=0; vector<int> vec(58,0); for(auto& c:s) { ++vec[c-'A']; } for(auto&t: vec) { re+=t/ 阅读全文
posted @ 2020-03-31 16:12 qiujiejie 阅读(97) 评论(0) 推荐(0)
摘要:class RandomizedCollection { unordered_map<int,unordered_set<int>> m; vector<int> vals; public: /** Initialize your data structure here. */ Randomized 阅读全文
posted @ 2020-03-31 11:40 qiujiejie 阅读(114) 评论(0) 推荐(0)
摘要:class Twitter { unordered_map<int,deque<pair<int,int>>> uid_tid;//deque is double-ended queue unordered_map<int,unordered_set<int>> uid_fid; int times 阅读全文
posted @ 2020-03-30 10:04 qiujiejie 阅读(140) 评论(0) 推荐(0)
摘要:1. class Solution { public: string getHint(string secret, string guess) { int bulls=0,cows=0; vector<int> m(10,0); queue<int> q; for(int i=0;i<guess.s 阅读全文
posted @ 2020-03-27 10:33 qiujiejie 阅读(155) 评论(0) 推荐(0)
摘要:class Solution { public: bool wordPattern(string pattern, string str) { istringstream is(str); unordered_map<char,string> m; unordered_map<string,char 阅读全文
posted @ 2020-03-27 09:51 qiujiejie 阅读(101) 评论(0) 推荐(0)
摘要:参考:https://www.cnblogs.com/grandyang/p/4781203.html class Solution { public: int hIndex(vector<int>& citations) { sort(citations.begin(),citations.end 阅读全文
posted @ 2020-03-26 11:36 qiujiejie 阅读(104) 评论(0) 推荐(0)
摘要:class Solution { public: bool isAnagram(string s, string t) { vector<int> ms(26,0),mt(26,0); for(auto& str:s) ++ms[str-'a']; for(auto& str:t) ++mt[str 阅读全文
posted @ 2020-03-26 10:46 qiujiejie 阅读(95) 评论(0) 推荐(0)
摘要:class Solution { public: int countPrimes(int n) { if(!n) return 0; vector<bool> isPrime(n,true); isPrime[0]=false;isPrime[1]=false; for(int i=2;i*i<n; 阅读全文
posted @ 2020-03-26 10:40 qiujiejie 阅读(121) 评论(0) 推荐(0)
摘要:1. class Solution { public: vector<string> findRepeatedDnaSequences(string s) { vector<string> re; unordered_map<string,int> m; if(s.empty()||s.size() 阅读全文
posted @ 2020-03-25 17:06 qiujiejie 阅读(115) 评论(0) 推荐(0)
摘要:参考:https://www.cnblogs.com/grandyang/p/4238577.html unordered_map<int,int> m: 余数到该余数对应的商在string中的映射;如果该余数已经出现过,说明开始循环了,在该余数对应的商前加上"(",在string的最后加上")", 阅读全文
posted @ 2020-03-25 16:13 qiujiejie 阅读(86) 评论(0) 推荐(0)
摘要:参考: https://www.cnblogs.com/grandyang/p/4579693.html https://www.iteye.com/blog/yiminghe-568666 三点共线问题判断 解法一:从第一个节点开始,找与它在同一条线上的;如果三点共线,则x2-x0/y2-y0=x 阅读全文
posted @ 2020-03-18 11:56 qiujiejie 阅读(135) 评论(0) 推荐(0)
摘要:参考:https://www.cnblogs.com/grandyang/p/4548184.html 基本思想是广度优先搜索,level表示当前已经放到路径中的word总数;每一次while循环,将当前这条路径(当前这个vector<string>)的下一个word的所有情况放入队列中,直到遇到了 阅读全文
posted @ 2020-03-17 16:25 qiujiejie 阅读(180) 评论(0) 推荐(0)
摘要:参考:https://www.cnblogs.com/grandyang/p/4281975.html https://blog.csdn.net/linhuanmars/article/details/23236995 动态规划的题 local[i][j]:到第i天最多进行j次交易,且最后一次交易 阅读全文
posted @ 2020-03-17 11:03 qiujiejie 阅读(124) 评论(0) 推荐(0)
摘要:/* // Definition for a Node. class Node { public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<Node 阅读全文
posted @ 2020-03-16 17:28 qiujiejie 阅读(89) 评论(0) 推荐(0)
摘要:/* // Definition for a Node. class Node { public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<Node 阅读全文
posted @ 2020-03-16 12:18 qiujiejie 阅读(104) 评论(0) 推荐(0)
摘要:迭代 /* // Definition for a Node. class Node { public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<N 阅读全文
posted @ 2020-03-16 12:00 qiujiejie 阅读(125) 评论(0) 推荐(0)
摘要:迭代 /* // Definition for a Node. class Node { public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<N 阅读全文
posted @ 2020-03-16 11:58 qiujiejie 阅读(92) 评论(0) 推荐(0)