Hello, for this question, we want to return the length of the length of the last word of a string. I was wondering why t
Posted: Fri May 20, 2022 10:41 am
Hello, for this question, we want to return the length of the
length of the last word of a string. I was wondering why the method
that I used returns the wrong number.
Thanks!
1 2 3 4 5 6 7 class Solution { public int lengthOfLastWord(String s) { String[] ary = s.split(""); for (int i = 0; i < ary.length; i++) { if (ary "") { return ary.length - i; == } } return 0 REBO Java } 11 12 } Testcase Run Code Result Debugger Wrong Answer Runtime: 0 ms Your input "Hello World" Output 0 Diff Expected 5
length of the last word of a string. I was wondering why the method
that I used returns the wrong number.
Thanks!
1 2 3 4 5 6 7 class Solution { public int lengthOfLastWord(String s) { String[] ary = s.split(""); for (int i = 0; i < ary.length; i++) { if (ary "") { return ary.length - i; == } } return 0 REBO Java } 11 12 } Testcase Run Code Result Debugger Wrong Answer Runtime: 0 ms Your input "Hello World" Output 0 Diff Expected 5