MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Lengthofword

Class Lengthofword

LeetCode/String/58. Length of Last Word/kaki5507.java:3–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1package leetcode;
2
3public class Lengthofword {
4
5 public static void main(String[] args) {
6 String s= "Hello worldss";
7 String s3=" ";
8 String s6 ="a ";
9
10 System.out.println(s6.length());
11// trim() 바깥의 공백 잘라줌
12// lastIndexOf로 뒤에서 찾아주고 -> 왼쪽부터 셈
13// String a = s.substring(s.trim().lastIndexOf(" ")-1,s.trim().length());
14// System.out.println(a.trim().length());
15
16
17 String str[] = s.split(" ");
18
19 if(str.length == 0) {
20 System.out.println(0);
21 }else
22 System.out.println(str[str.length-1].length());
23
24 }
25
26}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected