[Locked] Generalized Abbreviation
Write a function to generate the generalized abbreviations of a word.
Example:
Given word = "word", return the following list (order does not matter):
["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d","w3", "4"]
分析:
DFS或者BFS,按照规则将字母替换成数字,注意递归条件和参数的正确性
代码:
void dfs(string &str, vector<string> &vr, string cur, int count, int i) {
//Condition for ending
if(i == str.length()) {
if(count > )
cur += char(count + '');
vr.push_back(cur);
return;
}
//Stop converting the characters into numbers
if(count > )
dfs(str, vr, cur + char(count + '') + str[i], , i + );
else
dfs(str, vr, cur + str[i], , i + );
//Continue converting ....
dfs(str, vr, cur, count + , i + );
return;
}
vector<string> vs(string str) {
vector<string> vResults;
dfs(str, vResults, "", , );
return vResults;
}
[Locked] Generalized Abbreviation的更多相关文章
- [LeetCode] Generalized Abbreviation 通用简写
Write a function to generate the generalized abbreviations of a word. Example: Given word = "wo ...
- LeetCode Generalized Abbreviation
原题链接在这里:https://leetcode.com/problems/generalized-abbreviation/ 题目: Write a function to generate the ...
- [Swift]LeetCode320. 通用简写 $ Generalized Abbreviation
Write a function to generate the generalized abbreviations of a word. Example: Given word = "wo ...
- LeetCode 320. Generalized Abbreviation
原题链接在这里:https://leetcode.com/problems/generalized-abbreviation/ 题目: Write a function to generate the ...
- 【LeetCode】320. Generalized Abbreviation 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 日期 题目地址:https://leetcod ...
- 320. Generalized Abbreviation
首先想到的是DFS,对于每个单词的字母都遍历,比如 spy: 1py,s1y,sp1 然后每个遍历完的单词再DFS..左右有数字就合并比如 1py: 11y=>2py, 1p1 这样.. 但是单 ...
- [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写
A string such as "word" contains the following abbreviations: ["word", "1or ...
- [LeetCode] Valid Word Abbreviation 验证单词缩写
Given a non-empty string s and an abbreviation abbr, return whether the string matches with the give ...
- [LeetCode] Unique Word Abbreviation 独特的单词缩写
An abbreviation of a word follows the form <first letter><number><last letter>. Be ...
随机推荐
- 表达式:使用API创建表达式树(4)DynamicExpression
DynamicExpression:表示动态操作.这个网上可见的资料少得可怜,但想到MVC和第三方的动态语言能在NET运行.好奇的倒腾了下 先声明两个类(有相同的方法和字段,但不是继承于同一接口的类) ...
- Linux下inotify监控文件夹状态,发生变化后触发rsync同步
1.安装工具--inotifywget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar ...
- Android学习笔记(广播机制)
1.Android的广播机制介绍 收听收音机也是一种广播,在收音机中有很多个广播电台,每个广播电台播放的内容都不相同.接受广播时广播(发送方)并不在意我们(接收方)接收到广播时如何处理.好比我们收听交 ...
- ASP.NET实现二级域名(多用户,多商店)
本人所了解有两种方案,可能还有其的方式,希望大家多多讨论! 基本思路: 1. 域名支持泛解析,即是指:把A记录 *.域名.com 解析到服务器IP,服务器IIS中做绑定,绑定时主机头为空; 2. ...
- IE6解决固定定位代码
有些朋友在进行网页布局时,会遇到IE6浏览器不支持固定定位的兼容性问题,本博将详细介绍此问题的解决方法,需要了解的朋友可以参考下. ie6 垂直居中固定定位,代码如下: #center {_posit ...
- java逻辑运算符&&、&、||、|的详解
public class OperatorDemo{ public static void main(String args[]) { //当我们执行一下代码时会报错(&属于没短路的) if( ...
- Linux系统、版本、CPU、内存查看、硬盘空间
查看系统版本:lsb_release -a [root@localhost /]# lsb_release -a LSB Version: :core-4.0-amd64:core-4.0-no ...
- underscorejs-sample学习
2.22 sample 2.22.1 语法: _.sample(list, [n]) 2.22.2 说明: 从list中产生一个随机样本.传参n后返回n个随机元素,各元素不重复. 2.22.3 代码示 ...
- Asp.net 实现图片缩放 无水印(方法二)
public static System.Drawing.Image GetImage(string path) { try { if (path.StartsWith("http" ...
- 在Lufylegend中如何设置bitmap或者sprite的缩放和旋转中心
最近两天有个lufylegend游戏引擎群的群友需要做一个项目,其中要解决的需求是:获取照相机拍摄的图片,根据图片的EXIF信息让图片显示为“正常”情况,并且需要给图片添加一些事件侦听.何为正常呢?就 ...