We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
charAt i and i-1 are same. So you need to delete both of there characters.
The method: String.delete(int startindex, int endindex)
Here, startindex is included and endindex is excluded. That is, the charachters from startindex to endindex -1 will be deleted.
So the method will only delete i-1 th char if s.delete(i-1,i) is used.
Hence, s.delete(i-1,i+1) is used which will delete all the charachter from i-1 to i.
I hope this helps.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Super Reduced String
You are viewing a single comment's thread. Return to all comments →
charAt i and i-1 are same. So you need to delete both of there characters. The method: String.delete(int startindex, int endindex)
Here, startindex is included and endindex is excluded. That is, the charachters from startindex to endindex -1 will be deleted.
So the method will only delete i-1 th char if s.delete(i-1,i) is used. Hence, s.delete(i-1,i+1) is used which will delete all the charachter from i-1 to i.
I hope this helps.