我是靠谱客的博主 真实朋友,最近开发中收集的这篇文章主要介绍Leetcode c语言-Longest Substring Without Repeating Characters,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
Title:
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 subsequenceand not a substring.
题目是从一个字符串中找到最长的没有重复字符的子字符串。这道题目比较简单,就不多说解题思路,直接贴上c代码:
Solutions:
int lengthOfLongestSubstring(char* s) {
int len = 0;
int length = 1;
int last_length = 1;
int i;
while (s[len]) {
if (len >= 1) {
for (i = len - length; i <= len -1; i++) {
if (s[len] == s[i]) {
if (last_length < length)
last_length = length;
length = len -i;
break;
}
else if (i == len -1) {
length++;
if (last_length < length)
last_length = length;
}
}
}
len++;
}
if (len == 0)
return len;
return last_length;
}
最后
以上就是真实朋友为你收集整理的Leetcode c语言-Longest Substring Without Repeating Characters的全部内容,希望文章能够帮你解决Leetcode c语言-Longest Substring Without Repeating Characters所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复