一.两个难点算法 1.Manacher算法,线性时间求最长回文子串 2.KMP算法,字符串匹配问题,c语言中的strStr 二.几个题目 1.最长回文子串 方法:暴力,动态规划,中心扩展,manacher 参考: http://blog.163.com/zhaohai_1988/blog/static/2095100852012716105847112/ 2.最长回文子序列 3.最长公共子序列 4.最长公共子串…
1.单纯的Unicode 转码 String a = "\u53ef\u4ee5\u6ce8\u518c"; a = new String(a.getBytes("UTF-16"),"Unicode"); 2.String 字符串中含有 Unicode 编码时,转为UTF-8 public static String decodeUnicode(String theString) { char aChar; int len = theString…
/** * 方法名称:replaceBlank * 方法描述: 将string字符串中的换行符进行替换为"" * */ public static String replaceBlank(String str) { String dest = ""; if (str != null) { Pattern p = Pattern.compile("\t|\r|\n"); Matcher m = p.matcher(str); dest = m.re…
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters. Please note that the string does not contain any non-printable characters. Example: Input: "Hello, my name is John" Output:…
1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structure? 这道题让我们判断一个字符串中是否有重复的字符,要求不用特殊的数据结构,这里应该是指哈希表之类的不让用.像普通的整型数组应该还是能用的,这道题的小技巧就是用整型数组来代替哈希表,在之前Bitwise AND of Numbers Range 数…
Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b> and </b> to wrap the substrings in s that exist in dict. If two such substrings overlap, you need to wrap them together by only one pair of closed bold…
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string. Example 1: Input:s1 = "ab" s2 = "eidbaooo"…
package stringyiwen; //字符串中常用的方法public class StringTest03 { public static void main(String[] args) { String str = " ahgklajwggaal "; // System.out.println("字符串长度是:" + str.length()); // 返回一个字符串,其值为此字符串,并删除任何前导和尾随空格.//trim:vi. 削减; System…
统计字符串中的单词个数,这里的单词指的是连续的非空字符.请注意,你可以假定字符串里不包括任何不可打印的字符.示例:输入: "Hello, my name is John"输出: 5 详见:https://leetcode.com/problems/number-of-segments-in-a-string/description/ C++: 方法一: class Solution { public: int countSegments(string s) { int cnt=0; f…
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string. Example 1: Input:s1 = "ab" s2 = "eidbaooo"…