首页 > 其他 > 详细

eetCode刷题第二天——3Longest Substring Without repeating character 4 AddTwoList

时间:2019-06-07 13:41:40      阅读:381      评论:0      收藏:0      [点我收藏+]

混淆点:

  子串 连续

  子序列 可以不连续

知识点:

  HashMap:

出现问题:

  1.使用unordered_map头文件时报错

#error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.#end if

 

  解决方法:

  工程上右键,选择build options,在compiler settings里面,有列表,选择c++0x支持。

  PS:这个错误比较诡异的就是,他直接跳到了头文件里。所以可以知道这不是自己的错误,在工程里更改下编译方式就好了。  

  解决代码:

 1 //Leetcode #3
2 //题目描述:给定一个字符串求最大子串个数 5 6 #include<stdio.h> 7 #include<iostream> 8 #include<vector> 9 #include<unordered_map> 10 using namespace std; 11 12 13 class Solution { 14 public: 15 int lengthOfLongestSubstring(string s) 16 { 17 int res=0,left=-1,n=s.size(); 18 unordered_map<int,int> m; 19 for(int i=0;i<n;++i) 20 { 21 //count check whether s[i] exist 22 if(m.count(s[i])&&m[s[i]]>left) 23 { 24 left=m[s[i]]; 25 26 } 27 //update s[i]‘s position 28 m[s[i]]=i; 29 res=max(res,i-left); 30 31 } 32 return res; 33 } 34 }; 35 36 37 38 39 40 41 int main() 42 { 43 Solution s;//initializing object s 44 string str1="abttybacds"; 45 int t=0; 46 t=s.lengthOfLongestSubstring(str1); 47 cout<<t<<endl; 48 return 0; 49 }

 https://www.cnblogs.com/grandyang/p/4480780.html

这个里面还有其余几种方法的讲解

4.Median of Two Sorted Arrays两个有序数组的中位数 Hard

技术分享图片

 

eetCode刷题第二天——3Longest Substring Without repeating character 4 AddTwoList

原文:https://www.cnblogs.com/Marigolci/p/10987999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!