diff options
| author | Mistivia <i@mistivia.com> | 2025-09-01 21:52:38 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-09-01 21:52:38 +0800 |
| commit | 856f16f5d1ebbbaed25e89980a3401ea19e6d5ee (patch) | |
| tree | 9301c0840a5cb11a1f576d2eed5667a109a71eb2 /c/0058 | |
| parent | 19b55c0d3cec78ae26aed8b7d4a51a1e71a32a99 (diff) | |
solve 58
Diffstat (limited to 'c/0058')
| -rw-r--r-- | c/0058/main.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/c/0058/main.c b/c/0058/main.c new file mode 100644 index 0000000..6aff206 --- /dev/null +++ b/c/0058/main.c @@ -0,0 +1,21 @@ +int lengthOfLastWord(char* s) { + int i = 0; + int cur = 0; + int last = 0; + while (s[i] != '\0') { + if (s[i] == ' ') { + if (cur > 0) { + last = cur; + } + cur = 0; + } else { + cur++; + } + i++; + } + if (cur > 0) { + return cur; + } else { + return last; + } +}
\ No newline at end of file |
