作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/license-key-formatting/description/ 题目描述 You are given a license key represented as a string S which consists only alphanumeric character…
You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups by N dashes. Given a number K, we would want to reformat the strings such that each group contains ex…
problem 482. License Key Formatting solution1: 倒着处理,注意第一个字符为分隔符的情况要进行删除,注意字符的顺序是否正序. class Solution { public: string licenseKeyFormatting(string S, int K) { ) return NULL; ; string ans = ""; ; i>=; i--)//倒着处理. { char c = S[i]; if(S[i]=='-') c…
Question 482. License Key Formatting Solution 思路:字符串转化为char数组,从后遍历,如果是大写字母就转化为小写字母,如果是-就忽略,如果遍历了k个字符(排除-)就追加一个-. Java实现1:insert版(StringBuilder的append()与insert()效率比较) public String licenseKeyFormatting(String S, int K) { StringBuilder sb = new StringB…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-paths/description/ 题目描述: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either…
详见:https://leetcode.com/problems/license-key-formatting/description/ C++: class Solution { public: string licenseKeyFormatting(string S, int K) { string res = ""; int cnt = 0, n = S.size(); for (int i = n - 1; i >= 0; --i) { char c = S[i]; if…
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { public: string licenseKeyFormatting(string S, int K) { int len=S.length(); ; string res; ;i>=;i--) { char c=toupper(S[i]); if(c=='-') continue; res.push_b…
482. License Key Formatting Easy You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups by N dashes. Given a number K, we would want to reformat the strings…
[LeetCode]435. Non-overlapping Intervals 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/non-overlapping-intervals/description/ 题目描述: Given a collection of intervals, find the minimum number of…
[LeetCode]376. Wiggle Subsequence 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/wiggle-subsequence/description/ 题目描述: A sequence of numbers is called a wiggle sequence if the differences betw…