创办网站需要怎么做,asp网站建设教程,重庆大良网站建设,wordpress上传图片教程哈希表
哈希表主要是使用 map、unordered_map、set、unorerdered_set、multi_#xff0c;完成映射操作#xff0c;主要是相应的函数。map和set是有序的#xff0c;使用的是树的形式#xff0c;unordered_map和unordered_set使用的是散列比表的#xff0c;无序。
相应函数…哈希表
哈希表主要是使用 map、unordered_map、set、unorerdered_set、multi_完成映射操作主要是相应的函数。map和set是有序的使用的是树的形式unordered_map和unordered_set使用的是散列比表的无序。
相应函数
set multiset
相应的地址
map multimap
相应地址
unordered_map unordered_multimap
相应位置
unordered_set unordered_multiset
相应地址
刷题
无重复字符的最长子串 暴力的哈希操作最露比的方法肯定可以优化的emm标志位方法用一个记录上一个出现的位置从那里开始新的暴力操作。
class Solution {
public:int lengthOfLongestSubstring(string s) {int n s.length();int m 0;setchar mp;//最露的方法相当于暴力哈哈for(int i0;in;i){ mp.clear();int index 0;for(int ji;jn;j){if(mp.find(s[j])mp.end()){mp.insert(s[j]);index;}else{break;}}if(indexm) mindex;}return m;}
};
环形链表 class Solution {
public:bool hasCycle(ListNode *head) {setListNode* s;while(head!NULL){if(s.find(head)!s.end()){return true;}s.insert(head);head head-next;} return false;}
};相交链表 class Solution {
public:ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {setListNode* d;while(headA!NULL){d.insert(headA);headAheadA-next;}while(headB){if(d.find(headB)!d.end()){return headB;}headBheadB-next;}return NULL;}
};快乐数 class Solution {
public:bool isHappy(int n) {setint d;while(true){d.insert(n);if(n1)break;int sum 0;while(n){int d n%10;n/10;sum d*d;}nsum;if(d.find(n)!d.end()){return false;}}return true;}
};