Skip to content

Commit d762365

Browse files
authored
Merge pull request gzc426#300 from 018429/master
018429.md
2 parents 617078a + 43682e2 commit d762365

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

018429.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int firstUniqChar(char* s) {
2+
int ascii[256]={0};
3+
int i=0,len;
4+
while(s[i]!='\0')
5+
{
6+
i++;
7+
}
8+
len=i;
9+
for(i=0;i<len;i++)
10+
{
11+
ascii[s[i]]++;
12+
}
13+
i=0;
14+
while(ascii[s[i]]!=1&&i<len) i++;
15+
if(i==len)
16+
return -1;
17+
return i;
18+
}

2018.11.28-leetcode151/018429.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
int top=0;
2+
void push(char c,char* stack)
3+
{
4+
stack[top++]=c;
5+
}
6+
char pop(char* stack)
7+
{
8+
return stack[--top];//写入s1
9+
}
10+
void reverseWords(char *s) {
11+
int i=0,j=0,flag=0;
12+
while(s[i]!='\0') i++;
13+
char* stack = (char*)malloc(i);
14+
char* s1 = (char*)malloc(i+1);
15+
i--;
16+
while(i>=0)
17+
{
18+
if(s[i]==' ')
19+
{
20+
while(top!=0)//如果栈不为空
21+
{
22+
flag=1;
23+
s1[j++]=pop(stack);
24+
}
25+
if(flag==1)
26+
{
27+
s1[j++]=' ';
28+
flag=0;//重置flag
29+
}
30+
i--;
31+
}
32+
else
33+
{
34+
push(s[i--],stack);
35+
}
36+
}
37+
if(s[++i]!=' ')
38+
{
39+
while(top!=0)//如果栈不为空
40+
s1[j++]=pop(stack);
41+
s[j]=' ';
42+
}
43+
else
44+
j--;
45+
s1[j]='\0';
46+
s = strcpy(s,s1);
47+
free(s1);
48+
}

0 commit comments

Comments
 (0)