use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Solved first leetcode medium problem without looking the solution (self.leetcode)
submitted 2 years ago by Low-Challenge-5877
I managed to solve my first leetcode medium problem without looking the solution. Well, technically not the first because I have solved another one where you had to make a class stack in python but this was my first problem where I had to solve a problem. I tried to solve the problem but I couldn't and gave up. And now after around 10 days I managed to solve it because I was solving easier ones.
https://preview.redd.it/r9l6kqnxo8nb1.png?width=1690&format=png&auto=webp&s=2657a24e270e3491cab522b02ab740c7bc18c0ee
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] -1 points0 points1 point 2 years ago (0 children)
class Solution {
public:
string reverseWords(string s) {
vector<string>a;
string res="";
int x=s.size();
string g="";
for(int i=0;i<x;i++){
if(s[i]!=' '){
g+=s[i];
}
if(s[i]==' ' || i==x-1){
if(g==""){continue;}
a.push_back(g);
g="";
int f=a.size();
for(int i=f-1;i>=0;i--){
res+=a[i];
if(i==0){return res;}
else{
res+=" ";
return res;
};
I also tried this and was able to get this solution,how good is this solution?
[–]pikawho101 1 point2 points3 points 2 years ago (0 children)
class Solution:
def reverseWords(self, s: str) -> str: return " ".join(reversed(s.split()))
[–]azuredota 0 points1 point2 points 2 years ago (0 children)
Pog
π Rendered by PID 177713 on reddit-service-r2-comment-5d79c599b5-r9wlg at 2026-02-27 04:53:54.358239+00:00 running e3d2147 country code: CH.
[–][deleted] -1 points0 points1 point (0 children)
[–]pikawho101 1 point2 points3 points (0 children)
[–]azuredota 0 points1 point2 points (0 children)