Submission Detail

58 / 58 test cases passed.
Status:

Accepted

Runtime: 7 ms
Memory Usage: 40.9 MB
Submitted: 2 days, 20 hours ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0
1
2
3
4
5
6
7
8
9
10
11
12
10
20
30
40
50
60
java
You are here!
Your runtime beats 8.86 % of java submissions.
Runtime (ms)
Distribution (%)

0
1
2
3
4
5
6
7
8
9
10
11
12
20
40
60
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

40600
39900
40000
40100
40200
40300
40400
40500
40700
40800
40900
41000
41100
41200
41300
5
10
15
20
java
You are here!
Your memory usage beats 50.80 % of java submissions.
Memory (KB)
Distribution (%)

40600
39900
40000
40100
40200
40300
40400
40500
40700
40800
40900
41000
41100
41200
41300
5
10
15
20
Zoom area by dragging across this chart

Invite friends to challenge Length of Last Word


Submitted Code: 2 days, 20 hours ago

Language: java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution {
public int lengthOfLastWord(String s) {
s = s.strip();
int spaces = 0;
for (int i = 0; i < s.length(); i++)
if (s.charAt(i) == ' ')
spaces++;
if (spaces == 0) {
return s.length();
}
System.out.println("number of spaces = "+spaces);
int count = 0;
int length = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ')
count++;
if (count == spaces) {
for (int j = i+1; j < s.length(); j++)
length++;
break;
}
}
return length;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX