class Solution {
public:
string replaceDigits(string s) {
int n=s.size();
string p="";
for(int i=0;i<n;i++)
{
if((s[i]-'0')>=0 && (s[i]-'0')<=9)
{
p+=(s[i-1]+(s[i]-'0'));
}
else
{
p+=s[i];
}
}
return p;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter