Word “book” can be abbreviated to 4, b3, b2k, etc. Given a string and an abbreviation, return if the string matches the abbreviation. Assumptions: The original string only contains alphabetic characters. Both input and pattern are not null. Pattern w…
Symbols of String Pattern Matching in Introduction to Algorithms. As it's important to be clear when discussing the problem of string matching, we can use the meticulous symbols used in Introduction to Algorithms. Text: $T[1, ..., n]$. Pattern: $P[1,…
Given an original string input, and two strings S and T, replace all occurrences of S in input with T. Assumptions input, S and T are not null, S is not empty string Examples input = "appledogapple", S = "apple", T = "cat", i…
The function used here is from the leetcode. Details can be found in leetcode problem: Implement strStr() The best explanation should be made in the comments, which can be understood by the leading of code. // next[j]: the smallest valid position we…
An abbreviation of a word follows the form <first letter><number><last letter>. Below are some examples of word abbreviations: a) it --> it (no abbreviation) 1 b) d|o|g --> d1g 1 1 1 1---5----0----5--8 c) i|nternationalizatio|n --&…
Strings Immutable Strings Objects of the String class are immutable. Every method in the class that appears to modify a String actually creates and returns a brand new String object containing the modification. To the reader of the code, an argument…