-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram56.java
More file actions
56 lines (34 loc) · 1.12 KB
/
program56.java
File metadata and controls
56 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
557. Reverse Words in a String III
Easy
4.8K
226
Companies
Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
Input: s = "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Example 2:
Input: s = "God Ding"
Output: "doG gniD"
*/
package LeetCode;
public class program56 {
static String reverseWords(String s) {
String str = "";
String a[] = s.split(" ");
for(int i=0;i<a.length;i++){
String b = a[i];
for(int j=b.length()-1;j>=0;j--){
str += b.charAt(j);
}
str+=" ";
}
return str;
}
public static void main(String[] args) {
String s = "Let's take LeetCode contest";
String str = reverseWords(s);
System.out.println(str);
}
}