Skip to content

Commit 2af32eb

Browse files
solves length of last word
1 parent 89c9f31 commit 2af32eb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https://github.com/anishLearnsToCode/leetcode-algorithms)
44
![made-with-java](https://img.shields.io/badge/Made%20with-Java-1f425f.svg)
55
![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)
6-
![problems-solved](https://img.shields.io/badge/Problems%20Solved-12/1412-1abc9c.svg)
7-
![problems-solved-java](https://img.shields.io/badge/Java-12/1412-1abc9c.svg)
6+
![problems-solved](https://img.shields.io/badge/Problems%20Solved-13/1412-1abc9c.svg)
7+
![problems-solved-java](https://img.shields.io/badge/Java-13/1412-1abc9c.svg)
88
![problems-solved-python](https://img.shields.io/badge/Python-2/1412-1abc9c.svg)
99
[![license](https://img.shields.io/badge/LICENSE-MIT-<COLOR>.svg)](LICENSE)
1010
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)

src/LengthOfLastWord.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class LengthOfLastWord {
2+
public int lengthOfLastWord(String sentence) {
3+
String[] words = sentence.split(" ");
4+
if (words.length == 0) {
5+
return 0;
6+
}
7+
8+
return words[words.length - 1].length();
9+
}
10+
}

0 commit comments

Comments
 (0)