Longest Substring Without Repeating Characters(Time Limit Exceeded)
来源:互联网 发布:java html5 视频播放 编辑:程序博客网 时间:2024/06/12 00:09
问题
Given a string, find the length of the longest substring without repeating characters.
测试用例
Given "abcabcbb"
, the answer is "abc"
, which the length is 3.
Given "bbbbb"
, the answer is "b"
, with the length of 1.
Given "pwwkew"
, the answer is "wke"
, with the length of 3. Note that the answer must be a substring, "pwke"
is a subsequence and not a substring.
我的代码(Time Limit Exceeded)
func lengthOfLongestSubstring(s string) int { var maxLength int var tmpString string maxLength = 0 lengthOfString := len(s) //fmt.Println(lengthOfString) for i := 0; i < lengthOfString; i++{ for j:= i + 1; j <= lengthOfString; j++{ if j == lengthOfString { tmpString = s[i : ] }else{ tmpString = s[i : j] } //fmt.Println(tmpString, j - i) if checkRepeatingChar(tmpString) && (j - i) > maxLength{ maxLength = j - i } } } return maxLength}func checkRepeatingChar(s string) bool{ referenceOfs := s for i := 0; i < len(s); i++{ for j := 0; j < len(s); j++{ //fmt.Println(s[i], referenceOfs[j]) if i == j { continue }else if s[i] == referenceOfs[j]{ return false } } } return true}
我的代码(Accepted)
阅读全文
0 0
- Longest Substring Without Repeating Characters(Time Limit Exceeded)
- Longest Substring Without Repeating Characters(medium)
- Longest Substring Without Repeating Characters(C)
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- android root and su
- SpringMVC总结以及在面试中的一些问题
- 输入一棵二叉树,判断该二叉树是否是平衡二叉树。
- Git Problem—ortoiseGitPlink Fatal Error
- TCP流量控制和拥塞控制
- Longest Substring Without Repeating Characters(Time Limit Exceeded)
- What's the difference between arm-linux- / arm-none-linux-gnueabi- / arm-fsl-linux-gnueabi- in LTIB?
- GAN
- JVM垃圾收集器
- 运维基础——Win7自动化截图时的设置
- mysql视图的作用(详细)
- oracle中文乱码
- java excel导出工具类
- JavaScript小知识点(二):函数防抖和节流