日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

G面经prepare: Pattern Match

發(fā)布時間:2025/6/17 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 G面经prepare: Pattern Match 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
設(shè)定一個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 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/EdwardLiu/p/5143951.html

總結(jié)

以上是生活随笔為你收集整理的G面经prepare: Pattern Match的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。