Longest Substring Without Repeating Characters(C语言实现)
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.
题目地址:https://leetcode.com/problems/longest-substring-without-repeating-characters/
题目意思:给出一个字符串,输出最长的子串的长度,子串不能有重复的字符。(子串是连续的。)
解题思路: 依次读取字符串的每一个字符,如果第一次出现则当前子串长度+1,否则:首先判断当前长度是否大于最大长度,是则替换最大长度。然后
查找重复的字符是在原字符串哪里出现的。
代码如下:
int lengthOfLongestSubstring(char* s) { ,currlen = ; ], i, j, start = ; memset(table, , sizeof(table)); ; s[i] != '\0'; ++i){ ){ if (currlen > maxlen){ maxlen = currlen; } for(j = start; j < i; ++j){ //start记录重复的字符后一个位置 if (s[j] == s[i]){ table[s[j]] = ; start = j+; break; }else{ --currlen; table[s[j]] = ; } } }else{ ++currlen; } } if (currlen > maxlen){ maxlen = currlen; } return maxlen; }
Longest Substring Without Repeating Characters(C语言实现)的更多相关文章
- leetcode: longest substring without repeating characters
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...
- leetcode 3 Longest Substring Without Repeating Characters最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- LeetCode——Problem3:Longest Substring Without Repeating Characters
哎哟我天啊.这道题快折磨死我了.刚开始连题都没看明白,就是不知道substring是什么意思.研究了好长时间才看出来的. 光辉历史呀...菜死了 1.题目 Given a string, find t ...
- Leetcode 3. Longest Substring Without Repeating Characters(string 用法 水题)
3. Longest Substring Without Repeating Characters Medium Given a string, find the length of the long ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 3. Longest Substring Without Repeating Characters(c++) 15ms
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 【leetcode】Longest Substring Without Repeating Characters
题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
随机推荐
- 使用WCF的Trace与Message Log功能
原创地址:http://www.cnblogs.com/jfzhu/p/4030008.html 转载请注明出处 前面介绍过如何创建一个WCF Service http://www.cnblo ...
- Redis系列-好玩的用法
分布式锁 客户端执行如下命令,来获取锁和释放锁. random = random() ok = (Set key random PX 2000ms NX) if (ok) { //do somethi ...
- [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决
这篇文章主要讲述Python如何安装Numpy.Scipy.Matlotlib.Scikit-learn等库的过程及遇到的问题解决方法.最近安装这个真是一把泪啊,各种不兼容问题和报错,希望文章对你有所 ...
- php ajax 交互
html 页面 <body> <button id="oBtn">点击我</button> <script type="text ...
- VMware Tools安装小结
背景介绍:在VMware上装完ArchLinux后,窗口太小,操作不方便.查询后得知VMware Tools没有自动安装,需要手动安装. 官方安装说明:在 Linux 虚拟机中手动安装或升级 VMwa ...
- 由ArcMap属性字段自增引出字段计算器使用Python的技巧
1.前言 前些日子有人问我ArcMap中要让某个字段的值实现自增有什么方法?我首先想到像SQL Server中对于数值型字段可以设置自增.所以我打开ArcCatalog查看发现只提供默认值 ...
- Sql Server系列:字符串函数
字符串函数用于对字符和二进制字符串进行各种操作,大多数字符串函数只能作用于char.nchar.varchar和nvarchar数据类型.字符串函数可以用在SELECT或者WHERE语句中. 1. A ...
- <nginx.conf> nginx用户权限
Nginx用户权限 在nginx.conf文件的第一行一般是设置用户的地方(编译安装nginx时的参数--user=<user>也是指定用户的地方),如 user www www; 如不指 ...
- Plant Design Review Based on AnyCAD
Plant Design Review Based on AnyCAD eryar@163.com Abstract. AVEVA Review is used to 3D model visuali ...
- 深入理解JSON对象
× 目录 [1]语法规则 [2]stringify [3]parse[4]eval 前面的话 json(javascript object notation)全称是javascript对象表示法,它是 ...