arrow-up-a-zString

Notes and typical questions for String related problems

Notes

  • In Java, When joining String, new StringBuilder(s1).append(s2).toString() is faster than s1 + s2

Typical Questions

String Manipulation

  • 🌟 LC 344. Reverse String

  • LC 541. Reverse String II

  • 🌟 LC 151. Reverse Words in a String

    • The most important part is how to efficiently remove leading/trailing spaces and duplicate spaces between words. Make that logic simple enough!

  • Other platforms: Right shift of a string

    • It's not difficult, once you find the approach

  • LC 1768. Merge Strings Alternately

  • LC 345. Reverse Vowels of a String

  • LC 443. String Compression

  • LC 67. Add Binary

  • 🔴 LC 761. Special Binary String

KMP

  • Notes: the most important part is calculating next[]

  • 🌟 🟠 LC 28. Find the Index of the First Occurrence in a String

  • LC 459. Repeated Substring Pattern

    • A tricky way using next[] of KMP + Mathematical induction

String property

String Traversal

Simulation

Last updated