<!DOCTYPE html><html><head> <title></title></head><script type="text/javascript"> function search(str1,str2) { var i=j=k=a=jk=kk=0; var m=str1.length; var n=str2.length; var index=0; var maxlen=0; var st…
问题:有两个字符串str1和str2,求出两个字符串中最长公共字符串. 例如:“acbbsdef”和"abbsced"的最长公共字符串是“bbs” 算法思路: 1.把两个字符串分别以行和列组成一个二维矩阵. 2.比较二维矩阵中行和列对应的每个点的字符是否相同,是设置这个点为1,否设置这个点为0. 3.通过查找值为1的最长对角线来找到最长公共字符串. 通过上面str1和str2两个字符串,分别得出以行和列组成的一个二维矩阵如下图: 从上图可以看到,str1和str2共有3个公共子串&qu…
 //动态规划查找两个字符串最大子串         public static string lcs(string word1, string word2)         {             int max = 0;             int index = 0;             int[,] nums = new int[word1.Length + 1,word2.Length+1];             for (int i = 0; i <= word1.L…
  CreateTime--2017年2月28日09:37:06Author:Marydonjs判断是否包含指定字符串 var inputValue = "thunder://piaohua.com"; //方法一:使用indexOf()方法实现 if (inputValue.indexOf("thunder://") >= 0) { alert(1); } //自定义javascript的startWith()和endWith()方法 String.prot…
求公共子字符串问题(连续的) 这个题目是当时远景能源公司现场笔试的一道题目,当时根本就不知道动态规划是什么鬼,直接上来就暴力求解,面试官很谄媚的问我,你这能求出来吗?当时很年轻的说,能啊!现在想,当时哪来的自信和逗比勇气说这大话...在<进军硅谷>这本书上看到原题,我是懵逼,怎么想出这种解答出来的,下面直接上思路和代码. 思路: 定义二维数组dp[i][j]记录最大公共子串的长度, 若要返回字符串可以用s1.substring(i-dp[i][j]+1, i+1) 当s[i]==s[j]时,d…
1.js截取两个字符串之间的内容: var str = "aaabbbcccdddeeefff"; str = str.match(/aaa(\S*)fff/)[1]; alert(str);//结果bbbcccdddeee 2.js截取某个字符串前面的内容: var str = "aaabbbcccdddeeefff"; str = str.match(/(\S*)fff/)[1]; alert(str);//结果aaabbbcccddd 3.js截取某个字符串后…
[抄题]: Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in t. Example: Input: s = "abcd" t = &q…
match方法 var str = "iid0000ffr"; var substr = str.match(/id(\S*)ff/); console.log(substr) 返回结果为:["id0000ff", "0000"] ()里的\S*表达式匹配所有字符串 在高级语言里,我们会用一个叫数量词的概念: (?=ff)这表示以ff结尾的前面的字符串,但不包括ff var str = "iid0000ffr"; var su…
<script type="text/javascript"> var s='djh.doiwe.esd.d.ddd0sdd.d.'; var n=(s.split('.')).length-1; document.write(n); </script> 结果:6…
Freedom of Choice URAL - 1517 Background Before Albanian people could bear with the freedom of speech (this story is fully described in the problem "Freedom of speech"), another freedom - the freedom of choice - came down on them. In the near fu…