Skip to content

Instantly share code, notes, and snippets.

@natintosh
Created November 18, 2024 12:49
Show Gist options
  • Save natintosh/24febc5fd8162a8fd7d20de4317121c3 to your computer and use it in GitHub Desktop.
Save natintosh/24febc5fd8162a8fd7d20de4317121c3 to your computer and use it in GitHub Desktop.
Length of Last Word
void main() {
Solution solution = Solution();
// Test Case 1
String s1 = "Hello World";
print('Test Case 1:');
print('Input: "$s1"');
print('Expected Output: 5');
print('Actual Output: ${solution.lengthOfLastWord(s1)}');
print('');
// Test Case 2
String s2 = " fly me to the moon ";
print('Test Case 2:');
print('Input: "$s2"');
print('Expected Output: 4');
print('Actual Output: ${solution.lengthOfLastWord(s2)}');
print('');
// Test Case 3
String s3 = "luffy is still joyboy";
print('Test Case 3:');
print('Input: "$s3"');
print('Expected Output: 6');
print('Actual Output: ${solution.lengthOfLastWord(s3)}');
print('');
// Additional Test Cases
String s4 = "a"; // Single character
print('Test Case 4:');
print('Input: "$s4"');
print('Expected Output: 1');
print('Actual Output: ${solution.lengthOfLastWord(s4)}');
print('');
String s5 = "Hello"; // Single word
print('Test Case 5:');
print('Input: "$s5"');
print('Expected Output: 5');
print('Actual Output: ${solution.lengthOfLastWord(s5)}');
}
class Solution {
int lengthOfLastWord(String s) {
// TODO: Implement your solution here
return -1; // Placeholder return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment