<>1556. thousands separator

<>
analysis

* Split and splice from back to front , Finally, flip the output class Solution { public String thousandSeparator(int n)
{ if(n / 1000 == 0) return String.valueOf(n); // If n less than 1000, Then output directly without adding a separator
StringBuilder sb= new StringBuilder(); int count = 0; // How many digits are there now while(n > 0) {
if(count == 3) { // If there are already three , You need to add a separator , And set the number of times 0 sb.append("."); count = 0; } int temp =
n% 10; count++; sb.append(temp); n = n / 10; } return sb.reverse().toString();
} }
<>1576. Replace all question marks

<>
analysis

* One by one comparison class Solution { public String modifyString(String s) { char[] ch = s.
toCharArray(); for(int i = 0; i < ch.length; i++) { if(ch[i] == '?') {
// If the current character is ? char left = (i == 0 ? ' ' : ch[i - 1]); // Find the element on the left , And judge whether it is the first element char
right= (i == ch.length - 1 ? ' ' : ch[i + 1]); // Find the element on the right , And judge whether it is the last element char temp =
'a'; while(temp == left || temp == right) // Loop to find characters that are not the same as left and right characters temp++; ch[i] =
temp; } } return new String(ch); } }

Technology
Daily Recommendation