MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / reverseWords

Method reverseWords

Java/reverse-words-in-a-string.java:23–38  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

21*/
22class Solution {
23 public String reverseWords(String s) {
24 s = s.trim();
25
26 String [] strArr = s.split(" ");
27
28 String ans = "";
29
30 for (int i=strArr.length-1; i>=0; i--) {
31 if (strArr[i].isEmpty()){
32 continue;
33 }
34 ans += strArr[i].trim() + " ";
35 }
36
37 return ans.trim();
38 }
39}

Callers

nothing calls this directly

Calls 1

isEmptyMethod · 0.45

Tested by

no test coverage detected