FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #431 from liusuisui/master · feixiangcode/algorithm@6db2d20 · GitHub

Commit 6db2d20

Browse files
Merge pull request algorithm001#431 from liusuisui/master
1904056
2 parents f5f5b65 + 47fb06a commit 6db2d20

4 files changed

Lines changed: 81 additions & 1 deletion

File tree

‎Week_02/id_56/LeetCode_242_56.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

‎Week_02/id_56/LeetCode_671_56.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

‎Week_02/id_56/LeetCode_692_56.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

‎Week_02/id_56/NOTE.md‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff 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/

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL