-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add LeetCode problem 434 #1252
Conversation
Adds solution of problem 434 for leetcode. Beats 100% Time, 97.18% space
docs: updating `leetcode/DIRECTORY.md`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if to simplify the solution with only one loop? Something like that:
int countSegments(char * s){
int sLen = strlen(s);
int prevSpace = 1;
int result = 0;
char currChar;
for (int i = 0; i < sLen; i++){
currChar = s[i];
if (s[i] != ' ' && prevSpace){
result++;
}
prevSpace = (currChar == ' ');
}
return result;
}
It beats 100% also :)
@alexpantyukhin - Your version is simply superior, so I can't think of a good reason to not use it directly 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this PR is still valid, since I have pretty much copy-pasted your version apart from the comment. Please let me know
Both your contribution and @alexpantyukhin's contribution will be mentioned and kept, so I don't think there's much to worry about :) Thanks.
Adds solution of problem 434 for leetcode. Beats 100% Time, 97.18% space
Description of Change
References
Checklist