难度简单
解题思路:方法一:
(1)先将所有的‘-’删除;
(2)然后分组并在合适的位置插入‘-’;
时间复杂度:O(n^2);
空间复杂度O(1)
方法二:
逆序分组
时间复杂度O(n);
空间复杂度O(n);
下面是方法二的代码
*/
代码:
```cpp
class Solution {
public:
string licenseKeyFormatting(string s, int k) {
int len = s.length();
string str;
int count = 0;
for(int i = len - 1 ; i > -1 ;i--){
if(s[i]!='-'){
str.push_back(toupper(s[i]));
count++;
if(count/k==1){
str.push_back('-');
count = 0;
}
}
}
if(str.back()=='-' ){
str.pop_back();
}
reverse(str.begin(), str.end());
return str;
}
};
## 其他 toupper将小写字符转为大写的字符。



