aboutsummaryrefslogtreecommitdiff
path: root/Computer_Science/leetcode/58-length_of_last_word.c
blob: e1a9b97799aee06499d776071ab89458dbd257f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int lengthOfLastWord(char* s) {
	char* space;
	while(*s == ' ')
		s++;
	
	if(*s == '\0') return 0;
	space = s;
	while(*s != '\0') {
		if(*s == ' ' && *(s + 1) != ' ' && *(s + 1) != '\0')
			space = s;
		s++;
	}

	while(*(--s) == ' ');

	return *space == ' ' ? s - space : s - space + 1;
}