0 OR 9 || SPEED >100 % || MEMORY > 100% || > VOTRU
\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n      \n      string temp=to_string(num);\n      string temp2=to_string(num);\n      int n=tem
```\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n      \n      string temp=to_string(num);\n      string temp2=to_string(num);\n      int n=temp.length();\n     \n      int chI=-1;\n     \n      for(int i=0;i<n;i++)\n      {\n          if(temp[i]!=\'9\')\n          {\n              chI=i;\n              break;\n          }\n          \n      }\n        \n      if(chI!=-1)\n      {   \n          char c=temp[chI];\n          temp[chI]=\'9\';\n          \n          for(int i=chI+1;i<n;i++)\n          {\n              if(temp[i]==c)\n              {\n                  temp[i]=\'9\';\n              }\n          }\n      }\n            \n      int chI2=-1;\n      for(int j=0;j<n;j++)\n      {\n          if(temp2[j]!=\'0\')\n          {\n              chI2=j;\n              break;\n          }\n      }\n     // cout<<"chI2 "<<chI2<<endl;\n      if(chI2!=-1)\n      {\n          char c=temp2[chI2];\n          temp2[chI2]=\'0\';\n          for(int i=chI2+1;i<n;i++)\n          {\n              if(temp2[i]==c)\n              {\n                  temp2[i]=\'0\';\n              }\n          }\n      }\n        \n     int nums1=stoi(temp);\n     // cout<<nums1<<endl;\n      \n      int nums2=stoi(temp2);\n     // cout<<nums2<<endl;\n      return nums1-nums2;\n    }\n};\n```
['String']