随笔分类 - String
摘要:Write a function to find the longest common prefix string amongst an array of strings.public class Solution { public String longestCommonPrefix(String[] strs) { String compare =""; if(strs.length == 0) return compare; compare = strs[0]; for(int i = 1...
阅读全文
摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence.Note: The sequence of inte
阅读全文
摘要:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note:A word is defined as a character sequence consists of non-space characters only.For example,Givens="Hello Worl
阅读全文
摘要:Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a character正确的解出来方法是用二维的dp。假如我们要将字符串str1变成str2,sstr1(i)是s
阅读全文
摘要:Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack\遍历算法 1 public class Solution { 2 public String strStr(String haystack, String needle) { 3 4 if(haystack == null || needle == null) 5 return null; 6 if(needl...
阅读全文

浙公网安备 33010602011771号