482. License Key Formatting
static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
string licenseKeyFormatting(string S, int K)
{
int len=S.length();
int count=;
string res;
for(int i=len-;i>=;i--)
{
char c=toupper(S[i]);
if(c=='-')
continue;
res.push_back(c);
count++;
if(count==K)
{
res.push_back('-');
count=;
}
}
if(res.back()=='-')
res.pop_back();
reverse(res.begin(),res.end());
return res;
}
};
从后往前扫描,问题不大
482. License Key Formatting的更多相关文章
- 【leetcode】482. License Key Formatting
problem 482. License Key Formatting solution1: 倒着处理,注意第一个字符为分隔符的情况要进行删除,注意字符的顺序是否正序. class Solution ...
- 482. License Key Formatting - LeetCode
Question 482. License Key Formatting Solution 思路:字符串转化为char数组,从后遍历,如果是大写字母就转化为小写字母,如果是-就忽略,如果遍历了k个字符 ...
- [LeetCode] 482. License Key Formatting 注册码格式化
You are given a license key represented as a string S which consists only alphanumeric character and ...
- 【LeetCode】482. License Key Formatting 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 482 License Key Formatting 注册码格式化
详见:https://leetcode.com/problems/license-key-formatting/description/ C++: class Solution { public: s ...
- LeetCode_482. License Key Formatting
482. License Key Formatting Easy You are given a license key represented as a string S which consist ...
- [LeetCode] License Key Formatting 注册码格式化
Now you are given a string S, which represents a software license key which we would like to format. ...
- [Swift]LeetCode482. 密钥格式化 | License Key Formatting
You are given a license key represented as a string S which consists only alphanumeric character and ...
- LeetCode算法题-License Key Formatting(Java实现)
这是悦乐书的第241次更新,第254篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第108题(顺位题号是482).您将获得一个表示为字符串S的许可证密钥,该字符串仅包含字 ...
随机推荐
- leetcode748
public class Solution { public string ShortestCompletingWord(string licensePlate, string[] words) { ...
- java中正则表达式,编译报错:Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
转自:https://www.cnblogs.com/EasonJim/p/6561666.html 若出现:Invalid escape sequence (valid ones are \b ...
- c++builder 代码模板 code templates
c++builder6.0 MENU:Tools>Editor Options>Code Insight>Code templates XE6 c++builder D:\Prog ...
- 4 并发编程-(进程)-守护进程&互斥锁
一.守护进程 主进程创建子进程,然后将该进程设置成守护自己的进程,守护进程就好比崇祯皇帝身边的老太监,崇祯皇帝已死老太监就跟着殉葬了. 关于守护进程需要强调两点: 其一:守护进程会在主进程代码执行结束 ...
- salt之pillar组件
pillar也是salt最重要的组件之一,其作用是定义与被控主机相关的任何数据,定义好的数据可以被其他组件使用,如模板.state.API等.在pillar中定义的数据与不同业务特征的被控主机相关联, ...
- ActiveMQ安全设置:设置admin的用户名和密码
ActiveMQ使用的是jetty服务器, 打开conf/jetty.xml文件,找到 <bean id="securityConstraint" class="o ...
- ML_入门
N-gram 输入法后来提醒nlp自然语言理解一个向量映射到另一个空间,为什么是向量呢?模型其实是向量,一张图片表示成向量,像素表示成rgb ,每一个维度 数的度文本变成向量 one-hot repr ...
- .net数据库连接防注入参数查询 命令执行 读取 备份 导出导入转化XML格式
ADO.NET是一组类库,让我们通过程序的方式访问数据库.SYSTEM.DATA这个类提供了统一的接口访问Oracle MSSQL Access.像SYSTEM.IO类操作文件一样. **connec ...
- python引入模块时import与from ... import的区别(转)
import datetime是引入整个datetime包,如果使用datetime包中的datetime类,需要加上模块名的限定. 1 import datetime 2 3 print datet ...
- Spring boot集成 MyBatis 通用Mapper
配置 POM文件 <parent> <groupId>org.springframework.boot</groupId> <artifactId>sp ...