Given a string S and a string T, count the number of distinct subsequences ofT inS. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative po…
面试时会经常考这样的题目,估计也不让使用正则表达式.还好这个算法还算简单,不过在草稿纸上写难免会出现运行异常,好吧,面试官赢了,乃们屌丝就实实在在的把代码码出来吧. 谢谢“心扉”对我代码bug的纠正,现已想到更简便的方法,思路就是从被匹配字符串a中一个一个往后推,截取b字符串长度的字符串: public class CountHit { public static void main(String[] args) { String a = "123456abcde6a6abc6ab";…
#-*- coding:utf-8 -*- #取一个字符串中最多出现次数的词 import re from collections import Counter my_str = """ Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Sp…
dic=dict() d={} s=set() s='helloworld' (1)d=dict() for x in s: if x not in d.keys(): d[x]=1 else: d[x]=d[x]+1 print(d) (2)d2=dict() for x in s: d2[x]=d2.get(x,0)+1 print(d2) (3)d3=dict() for x in s: d3[x]=s.count(x) print(d3) 上面一共给出了三种方法,均是以字典的形式输出,但…
// // main.swift // 12- // // Created by wanghy on 15/8/9. // Copyright (c) 2015年 wanghy. All rights reserved. // //有一个字符串,统计每个字符出现的次数 //思路一:利用两个for循环进行嵌套 // var array = ["1","2","4","4","2","4&qu…
怪盗基德的挑战书 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 990 Accepted Submission(s): 478 Problem Description “在树最美丽的那天,当时间老人再次把大钟平均分开时,我会降临在灯火之城的金字塔前,带走那最珍贵的笑容.”这是怪盗基德盗取巴黎卢浮宫的<蒙娜丽莎的微笑>这幅画时,挑…
给定一个较短字符串shortStr='ab',和一个较长字符串longStr='adkdabkwelabwkereabrsdweo2342ablk234lksdfsdf1abe': 判断shortStr在longStr中出现的次数的方案,要求使用sql实现: 方案一:使用replace函数: ) ); set @llongStr='adkdabkwelabwkereabrsdweo2342ablk234lksdfsdf1abe'; set @shortStr='ab'; ); set @newS…