forked from akkupy/codeDump
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solved the daily checkin leetcode question
- Loading branch information
1 parent
136e2b3
commit 4c2f0cd
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
LeetCodeQuestions/557. Reverse Words in a String III/main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class main { | ||
public String reverseWords(String s) { | ||
String[] words = s.split(" "); | ||
StringBuilder reversed = new StringBuilder(); | ||
for (String word : words) { | ||
StringBuilder reversedWord = new StringBuilder(word); | ||
reversedWord.reverse(); | ||
reversed.append(reversedWord).append(" "); | ||
} | ||
return reversed.toString().trim(); | ||
} | ||
public static void main(String[] args) { | ||
main solution = new main(); | ||
|
||
String s1 = "Let's take LeetCode contest"; | ||
String result1 = solution.reverseWords(s1); | ||
System.out.println(result1); | ||
|
||
String s2 = "God Ding"; | ||
String result2 = solution.reverseWords(s2); | ||
System.out.println(result2); | ||
} | ||
} |