Skip to content

Commit

Permalink
solved the daily checkin leetcode question
Browse files Browse the repository at this point in the history
  • Loading branch information
sneha-4-22 committed Oct 1, 2023
1 parent 136e2b3 commit 4c2f0cd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions LeetCodeQuestions/557. Reverse Words in a String III/main.java
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);
}
}

0 comments on commit 4c2f0cd

Please sign in to comment.