Various pen questions for string operations

Source: Internet
Author: User

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             }

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.