We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b8813a8 commit 53e39c5Copy full SHA for 53e39c5
1859. Sorting the Sentence.cpp
@@ -0,0 +1,34 @@
1
+class Solution {
2
+public:
3
+ string sortSentence(string s) {
4
+
5
+ int n = s.size();
6
+ vector<pair<int,string>>temp;
7
8
+ int j = 0;
9
+ string ans = "";
10
+ while (j < n){
11
+ if( 48 <= s[j] && s[j] <= 57 ){
12
+ temp.push_back({s[j]-'0',ans});
13
+ ans = "";
14
+ j++;
15
+ }
16
17
+ if(s[j] == ' ') j++;
18
+ ans += s[j];
19
20
21
22
+ sort(temp.begin(),temp.end());
23
24
+ string ans1 = "";
25
+ for(auto it : temp){
26
+ ans1 += it.second;
27
+ ans1 += " ";
28
29
30
+ int m = ans1.size();
31
+ return ans1.substr(0,m-1);
32
33
34
+};
0 commit comments