文章标题
来源:互联网 发布:水果网络营销策划方案 编辑:程序博客网 时间:2024/05/21 18:41
leetcode 刷题日记
题目介绍
Given a string, find the length of the longest substring without repeating characters.
Examples:
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.
我的解决思路
因为昨天刚用了示波器,受到了启发。所以我一开始的想法是使用两个cursor,相当于一个游标的作用,在字符串中通过游标的移动来实现。但是,TMD这leetcode里的测试集也太精确了,这个方法我的逻辑错误太多,而且好多脚标也没搞清楚,所以最后放弃了。
这里贴一个这样思路的解决好像是C++?
吃完晚饭,我又受到了以前看的cctv2的一个推价格游戏的启发,这次这个代码提交了九次终于通过了。
s = 'abcabcbb'def long(s): k = 0 chi = "" for i in range(0,len(s)): if s[i] not in chi: chi = (chi + s[i]) if k < len(chi): k = len(chi) print("chi is "+chi) print("k is %d"%(k)) else: if k < len(chi): k = len(chi) chi = ""+chi[chi.find(s[i])+1:] +s[i] print(chi) print(k) return(k)print("=======================")print("s is "+s)print(long(s))
别人的解决思路
由于我没有学过数据结构,所以并不知道有哈希表这个东西。然后才看了大神是怎么做的哈希表做法
总结
做不出来先停一停,整理一下思路,不要死磕,不然会很坑。 转cs之路很漫长,小白从今天开始上路了。
阅读全文
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- WKWebView学习笔记
- 求链表的倒数第k个节点
- CentOS 7更改yum源与更新系统
- Pavel and barbecue
- Huffman Code(霍夫曼编码)原理及实例
- 文章标题
- 数据分析之《菜鸟侦探挑战数据分析》-6-r语言-时间序列-逻辑回归分析-自相关-日历图
- 数组的本质分析
- JavaScript高级程序设计(第3版)笔记(四)
- FPGA基础-异步复位,同步释放
- ubuntu下mysql出现 warning: Changed limits: max_connections: 214 问题
- bingo小游戏(圈圈叉叉小游戏)python
- Java中对Array数组的常用操作,交集并集合集!
- php 在LINUX下创建目录失败的解决方法