leetcode_middle_33_482. License Key Formatting
来源:互联网 发布:医保报销软件 编辑:程序博客网 时间:2024/05/01 23:16
题意:
将一个序列号中的分隔符‘-’删除,再把字母都换成大写。然后每隔K个加一个分隔符‘-’,重新分隔成若干个子序列,(第一个子序列字符个数可以小于等于K个)
分析:
这题思路是直接的至于实现,一看分隔,变大写这些,明显是大量使用String类的方法...
我们需要做的是去掉“-”,变大写,加上它,而且这几者之间是互不影响的。
为了避免过多的条件判断,我们反向处理每次角标减去K的方式来加上“-”
public class Solution { public String licenseKeyFormatting(String str, int k) { StringBuilder sb = new StringBuilder(str.toUpperCase().replaceAll("-","")); for(int i = sb.length()-k; i>0; i-=k) sb.insert(i, "-"); return sb.toString(); }}
0 0
- leetcode_middle_33_482. License Key Formatting
- 482. License Key Formatting
- 482. License Key Formatting**
- leetcode482: License Key Formatting
- License Key Formatting
- 482. License Key Formatting
- License Key Formatting
- 482. License Key Formatting
- 482. License Key Formatting
- LeetCode 482. License Key Formatting
- [leetcode] 482. License Key Formatting
- 【Leetcode】482. License Key Formatting
- 482. License Key Formatting (M)
- LeetCode 482. License Key Formatting
- [leetcode]482. License Key Formatting
- [LeetCode]482. License Key Formatting
- LeetCode 482. License Key Formatting
- leetcode 482. License Key Formatting
- 从jvm的角度来看java的多线程
- oj1070
- Android ubuntu录制手机 GIF 视频
- html5新特性-----离线存储
- GCD入门(四): 完结
- leetcode_middle_33_482. License Key Formatting
- linux线程编程出错
- PHP环境搭建(1)——安装Apache
- hiho一下 第136周-优化延迟(二分)
- 如何本地调试Storm topology
- Data.parse()与Data()
- Tensorflow在windows7下的安装
- 从“马云说”看中国制造
- [LeetCode]Next Greater Element