[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 ...
随机推荐
- equals函数的作用
1.equals函数在什么地方 在Object类中,写法与==一样,但是我们用的时候要重写这个equals方法 String类型中的equals是复写好的 2.equals函数的作用 ==号在比较两个 ...
- Android OpenGL ES 3.0 纹理应用
本文主要演示OpenGL ES 3.0 纹理演示.接口大部分和2.0没什么区别,脚本稍微有了点变化而已. 扩展GLSurfaceView package com.example.gles300; im ...
- Android平台的四大天王:Activity, Service, ContentProvider, BroadcastReceiver
今天开始要自学android,刚看到百度知道上面这段话,觉得不错(不过已经是2011年8月的回答了): Android系统的手机的每一个你能看到的画面都是一个activity,它像是一个画布,随你在上 ...
- power desinger 学习笔记<八>
转-PowerDesigner 把Comment复制到name中和把name复制到Comment 在使用PowerDesigner对数据库进行概念模型和物理模型设计时,一般在NAME或Comment中 ...
- IOS常用开源库
转自:http://www.csdn.net/article/2013-06-18/2815806-GitHub-iOS-open-source-projects-two/1 1. AFNetwork ...
- xml有哪些解析技术?区别是什么?
xml有哪些解析技术?区别是什么? Answer: 有DOM,SAX,STAX等 (1):DOM:处理大型文件时其性能下降的非常厉害.这个问题是由DOM的树结构所造成的,这种结构占用的内存较多,而且D ...
- 通常我们使用[NSDate date]方法得到的时间与当前时间不一致,如何解决?
NSDate *date = [NSDate date]; NSTimeZone *zone = [NSTimeZone systemTimeZone]; NSInteger interv ...
- 浅谈angular框架
最近新接触了一个js框架angular,这个框架有着诸多特性,最为核心的是:MVVM.模块化.自动化双向数据绑定.语义化标签.依赖注入,以上这些全部都是属于angular特性,虽然说它的功能十分的强大 ...
- 【HDU4366】【DFS序+分块】Successor
Problem Description Sean owns a company and he is the BOSS.The other Staff has one Superior.every st ...
- 关于Linux 交互(用户操作接口)
Linux 系统提供两种基本接口给用户操作:命令行,图形界面. 不同接口也有相应的访问终端. 一.命令行 Command Line Linux系统命令行,一般指 Shell. Shell 接受经键盘输 ...