Skip to content

Commit

Permalink
将有序数组转换为二叉搜索树
Browse files Browse the repository at this point in the history
  • Loading branch information
money89757 authored Jul 5, 2018
1 parent 922e8c2 commit 900f4cc
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions 算法/LeetCode/lengthOfLongestSubstring.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int lengthOfLongestSubstring(char *s)
{
int buf[128];
int max = 0;
int len = 0;
int index = 0;

memset(buf,0xff,sizeof(buf));

while(*s != '\0'){
if(buf[*s] == -1){
len++;
}else{
if(index - buf[*s] > len){
len ++;
}else{
len = index - buf[*s];
}
}
if(len > max)
max = len;
buf[*s++] = index++;
}

return max;

}

int main(int argc, const char *argv[])
{
int num;
char *str = "AbcdABCDABCDE";

printf("1\n");
num = lengthOfLongestSubstring(str);
printf("maxstring = %d\n",num);
return 0;
}

0 comments on commit 900f4cc

Please sign in to comment.