| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + bool isAnagram(string s, string t) { | ||
| 2 | + if(s.size() != t.size()) return false; | ||
| 3 | + vector<int> just(26, 0); | ||
| 4 | + for(int i=0; i<s.size(); i++){ | ||
| 5 | + just[s[i]-'a']++; | ||
| 6 | + just[t[i]-'a']--; | ||
| 7 | + } | ||
| 8 | + for(int p: just) | ||
| 9 | + if(p!=0) | ||
| 10 | + return false; | ||
| 11 | + return true; | ||
| 12 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + class Solution { | ||
| 2 | + public: | ||
| 3 | + vector<int> nums; | ||
| 4 | + int findSecondMinimumValue(TreeNode* root) { | ||
| 5 | + storeNums(root); | ||
| 6 | + set<int> st(nums.begin(), nums.end()); | ||
| 7 | + if(st.size()==1){ | ||
| 8 | + return -1; | ||
| 9 | + } | ||
| 10 | + //sort(st.begin(), st.end()); | ||
| 11 | + set<int>::iterator it; | ||
| 12 | + it = st.begin(); | ||
| 13 | + it++; | ||
| 14 | + return *it; | ||
| 15 | + } | ||
| 16 | + void storeNums(TreeNode* root){ | ||
| 17 | + if(root==NULL){ | ||
| 18 | + return; | ||
| 19 | + } | ||
| 20 | + nums.push_back(root->val); | ||
| 21 | + storeNums(root->left); | ||
| 22 | + storeNums(root->right); | ||
| 23 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,24 @@ | |||
| 1 | + vector<string> topKFrequent(vector<string>& words, int k) { | ||
| 2 | + //1.[] 2.find insert 3.insert | ||
| 3 | + map<string,int> countmap; | ||
| 4 | + //将字符串按照字母顺序排序,并统计出字符串出现的次数 | ||
| 5 | + for(auto& e : words) | ||
| 6 | + countmap[e]++; | ||
| 7 | + | ||
| 8 | + multimap<int,string,greater<int>> sortmap;//出现次数为key,字符串为value | ||
| 9 | + //按照出现次数从大到小进行排序 | ||
| 10 | + for(const auto& kv:countmap) | ||
| 11 | + { | ||
| 12 | + sortmap.insert(make_pair(kv.second,kv.first)); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + vector<string> v; | ||
| 16 | + multimap<int,string>::iterator it = sortmap.begin(); | ||
| 17 | + while(it != sortmap.end() && k--) | ||
| 18 | + //遍历排好序的map取出前k个出现频率最高的字符串放入vector中 | ||
| 19 | + { | ||
| 20 | + v.push_back(it->second); | ||
| 21 | + ++it; | ||
| 22 | + } | ||
| 23 | + return v; | ||
| 24 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1 +1,22 @@ | |||
| 1 | - # 学习笔记 | ||
| 1 | + # 学习笔记 | ||
| 2 | + 第二周题目 | ||
| 3 | + 哈希表 | ||
| 4 | + 简单:https://leetcode-cn.com/problems/valid-anagram/ | ||
| 5 | + 中等:https://leetcode-cn.com/problems/top-k-frequent-words | ||
| 6 | + 中等:https://leetcode-cn.com/problems/find-duplicate-file-in-system/ | ||
| 7 | + 困难:https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/ | ||
| 8 | + 困难:https://leetcode-cn.com/problems/number-of-atoms/ | ||
| 9 | + | ||
| 10 | + 二叉树 | ||
| 11 | + 简单:https://leetcode-cn.com/problems/second-minimum-node-in-a-binary-tree/ | ||
| 12 | + 中等:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/ | ||
| 13 | + 中等:https://leetcode-cn.com/problems/all-nodes-distance-k-in-binary-tree/ | ||
| 14 | + 困难:https://leetcode-cn.com/problems/count-of-smaller-numbers-after-self/ | ||
| 15 | + 困难:https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/ | ||
| 16 | + | ||
| 17 | + 二叉搜索树 | ||
| 18 | + 简单:https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/ | ||
| 19 | + 中等:https://leetcode-cn.com/problems/range-sum-of-bst/ | ||
| 20 | + 中等:https://leetcode-cn.com/problems/contains-duplicate-iii/ | ||
| 21 | + 困难:https://leetcode-cn.com/problems/count-of-range-sum/ | ||
| 22 | + 困难:https://leetcode-cn.com/problems/count-of-smaller-numbers-after-self/ | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments