Reverse Words In A Given String Geeks For Geeks
Problem Link: Its also Problem Of Day 29 January https://practice.geeksforgeeks.org/problems/reverse-words-in-a-given-string5459/1 Solution: class Solution { //Function to reverse words in a given string. String reverseWords(String s) { StringBuilder sb=new StringBuilder(); Stack<String>stack=new Stack<String>(); for(int i=0;i<s.length();i++){ if(s.charAt(i)=='.'){ stack.add(sb.toString()); sb.setLength(0); } else{ sb.append(s.charAt(i)); } ...