G面经prepare: Pattern Match
设定一个pattern 把 'internationalization' 变成 'i18n', 比如word是house,pattern可以是h3e, 3se, 5, 1o1s1等, 给pattern和word,判断是否match,
1 package DataStreamAverage; 2 3 public class Solution3 { 4 public boolean check(String s1, String s2) { 5 return helper(s1, 0, s2, 0); 6 } 7 8 public boolean helper(String s1, int i1, String s2, int i2) { 9 if (i1==s1.length() && i2==s2.length()) return true; 10 if (i1==s1.length() || i2==s2.length()) return false; 11 if (isDigit(s2.charAt(i2))) { 12 int num = 0; 13 while (i2<s2.length() && isDigit(s2.charAt(i2))) { 14 num = num*10 + (int)(s2.charAt(i2)-'0'); 15 i2++; 16 } 17 if (i1+num > s1.length()) return false; 18 return helper(s1, i1+num, s2, i2); 19 } 20 else { 21 if (s1.charAt(i1) != s2.charAt(i2)) return false; 22 return helper(s1, i1+1, s2, i2+1); 23 } 24 } 25 26 public boolean isDigit(char c) { 27 if (c>='0' && c<='9') return true; 28 else return false; 29 } 30 31 32 /** 33 * @param args 34 */ 35 public static void main(String[] args) { 36 // TODO Auto-generated method stub 37 Solution3 sol = new Solution3(); 38 boolean res = sol.check("houskjfjjdkse", "h11e"); 39 if (res) System.out.println("True"); 40 else System.out.println("false"); 41 } 42 43 }
转载于:https://www.cnblogs.com/EdwardLiu/p/5143951.html
G面经prepare: Pattern Match相关推荐
- LPC43xx SGPIO Pattern Match Mode
模式匹配 所有位串均具有模式匹配功能. 该功能可用于检测启动代码等.要使用该功能,则必须用需匹配的模式来对REG_SS 编程 (请注意, POS 达到零时 REG_SS 不会与 REG 交换!) M ...
- G面经prepare: Reorder String to make duplicates not consecutive
字符串重新排列,让里面不能有相同字母在一起.比如aaabbb非法的,要让它变成ababab.给一种即可 Greedy: 跟FB面经Prepare task Schedule II很像,记录每个char ...
- G面经prepare: Set Intersection Set Difference
求两个sorted数组的intersection e.g. [1,2,3,4,5],[2,4,6] 结果是[2,4] difference 类似merge, 分小于等于大于三种情况,然后时间O(m+n ...
- php正则中不支持g修饰符吗,Pattern Modifiers – 规则表达式的修饰符(转载)发现PHP里有些正则表达式的应用和PERL里的不一样。。所…-PHP教程,PHP应用...
pattern modifiers – 规则表达式的修饰符 下面是当前规则表达式里可用的修饰. 括号内的名字是那些修饰符的内部 pcre 名字. i (pcre_caseless) 如果设置了这个修饰 ...
- G面经prepare: Straight Partition of A Deck of Cards
Define "Straight" as 5 cards with consecutive numbers. Determine if the deck can be fully ...
- 基于Python的中英文分词基础:正则表达式和jieba分词器
基于Python的中英文分词基础:正则表达式和jieba分词器 前言介绍 英文字符串处理 Python中的str 正则表达式 Python中的正则表达式模块 re 小练习 字符串中出现频次最多的字母 ...
- 翻译:java.util.regex.Pattern
java.util.regex.Pattern A compiled representation of a regular expression. A regular expression(正则表达 ...
- PEP 634 – Structural Pattern Matching: Specification
PEP 634 – Structural Pattern Matching: Specification PEP 634 – 结构化模式匹配:规范 PEP: 634 Title: Structural ...
- 论文翻译——Multi-Constrained Graph Pattern Matching in Large-Scale Contextual Social Graphs
文章目录 Abstract 附加 Introduction Background 附加 Problem 附加 Contribuitions 附加 Related Work (1) 附加 (2) 附加 ...
最新文章
- 博客园的“随笔、文章、新闻、日记有啥区别”
- matlab训练集测试集划分
- CTF-RSA共模攻击 和 非共模攻击解密脚本
- value proposition canvas
- spring jmx_JMX和Spring –第1部分
- 不把C作为第一门语言是个好主意么?
- android体系结构中每层的功能,Android体系结构
- CUDA精进之路(五):图像处理——OTSU二值算法(最大类间方差法、大津法)
- 2018电工杯数学建模A题
- Webstorm汉字乱码时
- c语言追赶法求方程组的解,MATLAB-追赶法求解三对角方程组的算法原理例题与程序...
- SAP中物料需求计划不考虑库存策略应用案例
- 零一块学计算机二级题库,2017年计算机二级office题库及答案
- EDEM创建用于模拟颗粒工厂的多边形后,选中多边形视图中不显示红色多边形
- C#开启路由器upnp功能
- GIS开源软件大全(备用)
- 女生戴蓝牙耳机什么颜色好看?适合女生的高颜值蓝牙耳机
- 红米7 自编译不完美 twrp 可root手机
- 计算机视觉中的数据流与模型训练代码总结!
- 自动在副屏/虚拟屏启动100%鲜橙汁 | 可用于上班摸鱼
热门文章
- Ant在MyEclipse中的配置总结
- 特征选择和特征生成问题初探
- 第一章:火狐浏览器 : 环境配置: FireFox 版本38 + jdk 7 + selenium 2.53.6 + selenum-version 2.48.2...
- 17、Spring Boot普通类调用bean【从零开始学Spring Boot】
- shell-sed命令详解(转)
- 常见虚拟主机目录对照及星外提权目录
- 多个中间件_前端如何正确使用中间件?
- hdu4864 贪心
- C语言经典例14-将一个正整数分解质因数
- 【Android 逆向】应用数据目录 ( files 数据目录 | lib 应用自带 so 动态库目录 | databases sqlite3 数据库目录 | cache 缓存目录 )