The following lists some questions about string operations that often appear in the written test. They are all written by myself. If there is anything wrong or there is a better implementation, you are welcome to point out! If you have other questions, please post them! Thank you!
1. Implement string inversion. For example, input "abc" and return "CBA"
System.out.println(inverse("liuling" [] chars = str.toCharArray(); ( i = 0; i < chars.length/2; i++ temp = chars[i] = chars[chars.length-i-1 chars[chars.length-i-1] = }
2. Find the longest symmetric string in the string
System.out.println(findSymmetry("dgaabcddcbadfabcdefghijkkjihgfedcbagaaabbccddddccbbaaaf" ( i = str.length()-1; i > 0; i--) { ( j = 0; j<str.length() && j+i<str.length(); j++ symmetryStr = str.substring(j, j+i+1 [] chars = (k = 0; k < chars.length/2; k++ (chars[k] != chars[chars.length-k-1 (k == chars.length/2 "" }
3. Calculate the number of symmetric strings in a string
System.out.println(findSymmetryCount("aabbaaffddphpaffa" count = 0 ( i = 1; i < str.length(); i++ ( j = 0; j<str.length() && j+i<str.length(); j++ symmetryStr = str.substring(j, j+i+1 [] chars = (k = 0; k < chars.length/2; k++ (chars[k] != chars[chars.length-k-1 (k == chars.length/2 count++ }
4. Find the characters with the highest frequency in the string
System.out.println(findHighRateChar("abcdfeeafdaf" max = 0 c = ' ' Map<Character, Integer> map = HashMap<Character, Integer> [] chars = ( i = 0; i < chars.length; i++ map.put(chars[i], map.get(chars[i])+1 (map.get(chars[i])> max = c = } map.put(chars[i], 1 }