LeetCode 第四题
来源:互联网 发布:snh48知乎 直弯 编辑:程序博客网 时间:2024/06/06 00:54
Longest Substring Without Repeating Characters
使用ASCII码作为Hash函数
借鉴KMP算法,加速滑动速度
LeetCode Time 4ms
#include <stdio.h>
#include <memory.h>#define CHAR_NUMBER 128
#define BUFFER_SIZE sizeof(char*) * CHAR_NUMBER
int lengthOfLongestSubstring(char* s)
{
char* HashTable[CHAR_NUMBER];
memset(HashTable, 0, BUFFER_SIZE);
char* pHead = s;
char* pTail = s;
int Length = 0;
int BestLength = 0;
while(*pTail)
{
if (!HashTable[*pTail])
{
HashTable[*pTail] = pTail;
++Length;
++pTail;
}
else
{
int Distance = pTail - HashTable[*pTail];
BestLength = Length < BestLength ? BestLength : Length;
Length = Distance;
char* pTemp = pHead;
while (pTemp < HashTable[*pTail])
{
HashTable[*pTemp] = 0;
++pTemp;
}
pHead = HashTable[*pTail] + 1;
HashTable[*pTail] = pTail;
++pTail;
}
}
return Length > BestLength ? Length : BestLength;
}
0 0
- LeetCode 第四题
- leetcode 第四题
- LeetCode 算法第四题
- LeetCode第四题,Add Two Numbers
- 每天一题LeetCode[第四天]
- Leetcode第四周周赛
- leetcode第四题:Median of Two Sorted Arrays (java)
- Leetcode第四题_Median of Two Sorted Arrays
- Leetcode第四题 Median of Two Sorted Arrays
- Leetcode: 第四题 Median of Two Sorted Arrays
- leetcode第四题 Median of Two Sorted Arrays
- leetcode:67 Add Binary-每日编程第四十三题
- leetcode小白解题记录——第四题
- LeetCode 第四十二题(Trapping Rain Water) Java
- LeetCode 第四十三题(Multiply Strings)Java
- LeetCode 第四十五题(Jump Game II)Java
- Leetcode 第四题< Median of Two Sorted Arrays>(Java)
- leetcode 第四题 Median of Two Sorted Arrays
- Android 之gravity 和layout_Gravity属性
- springmvc常用注解
- 《集体智慧编程》——分级聚类的实现
- 黑马程序员——java中泛型的简述
- IEEE 802.1P
- LeetCode 第四题
- sencha grid列tooltip提示
- ext 类似百度、google搜索自动提示
- iOS 实现截屏效果 OC保存屏幕为图片
- 第十一周 项目2-职员有薪水了(2)
- 开源项目,源码
- js实现翻牌效果
- mysql分表的3种方法
- MongoDB常用操作命令大全