LeetCode Algorithms3: Longest substring without repeating characters(in swift)
来源:互联网 发布:淘宝官方活动报名 编辑:程序博客网 时间:2024/05/29 16:56
LeetCode algorithms 3
Problem:
Give a string, find the length of the longest substring without repeating characters.
Examples:
Give"abcabcbb"
, the answer is"abc"
,which the length is 3.
Given"pwwkew"
,the answer is"wke"
,with the length is 3. Note that the answer must be a substring,"pwke"
is a subsequence and not a substring.
Code( in swift ):
class Solution { func lengthOfLongestSubstring(s: String) -> Int{ var j = 0, ret = 0 var charAt = [Int](count:256, repeatedValue:0) if s.isEmpty { return 0 } var i = 0 for c in s.utf8{ if charAt[Int(c)]>j{ if i-j>ret{ ret = i-j } j = charAt[Int(c)] } charAt[Int(c)] = i+1 i+=1 } return (i-j>ret) ? (i-j) : ret }}
Time complexity:
Space complexity:
0 0
- LeetCode Algorithms3: Longest substring without repeating characters(in swift)
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- Object-c 不错的视频教程
- Guest OS, Qemu, KVM工作流程
- AIDL的Proxy-Stub理解:(以实际媒体播放器服务单独运行在一个进程中为例)
- 短信验证具体步骤
- UITableViewCell 的Image设置了UIViewContentModeScaleAspectFill后图片超出去了
- LeetCode Algorithms3: Longest substring without repeating characters(in swift)
- centos 7 mysqlhotcopy 安装,使用 笔记
- Netlink实现热拔插监控
- MySQL 数据备份与还原
- zabbix监控报错zabbix server is not running: the information displayed may not be current
- Kali linux
- 史上最全的环信iOS 2.x and 3.x SDK单聊的集成方案!
- SEO终极算法(三),百度排名引流So easy
- KVM虚拟机创建功能详细讲解