From e3afd3dfa3c8370914f315b6eb393534b7f893a9 Mon Sep 17 00:00:00 2001 From: julienChemillier <66684524+julienChemillier@users.noreply.github.com> Date: Thu, 27 Oct 2022 09:28:45 +0200 Subject: [PATCH 1/2] Add 58 in c language --- c/58-length-of-the-last-word.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 c/58-length-of-the-last-word.c diff --git a/c/58-length-of-the-last-word.c b/c/58-length-of-the-last-word.c new file mode 100644 index 000000000..769667fb8 --- /dev/null +++ b/c/58-length-of-the-last-word.c @@ -0,0 +1,25 @@ +/* +Given a string s consisting of words and spaces, return the length of the last word in the string. + +Space: O(1) +Time: O(n) +*/ + +int lengthOfLastWord(char * s){ + int last_space=-1; // Index of the last ' ' + int last_word=0; // Length of the last word + int i; + for (i=0; s[i]!='\0'; i++) { + if (s[i]==' ') { + if (last_space != (i-1)) { + last_word = i-last_space -1; + } + last_space = i; + } + } + if (last_space == (i-1)) { // if the length wanted is already in last_word + return last_word; + } else { + return i-last_space-1; + } +} From b76f2060c8f972d3757e900b0ce9cf03a1594625 Mon Sep 17 00:00:00 2001 From: aa0 <71089234+Ahmad-A0@users.noreply.github.com> Date: Wed, 2 Nov 2022 22:28:31 +0000 Subject: [PATCH 2/2] Rename 58-length-of-the-last-word.c to 58-Length-Of-The-Last-Word.c --- c/{58-length-of-the-last-word.c => 58-Length-Of-The-Last-Word.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename c/{58-length-of-the-last-word.c => 58-Length-Of-The-Last-Word.c} (100%) diff --git a/c/58-length-of-the-last-word.c b/c/58-Length-Of-The-Last-Word.c similarity index 100% rename from c/58-length-of-the-last-word.c rename to c/58-Length-Of-The-Last-Word.c
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: