Returns true if it is possible to make a equals b (if b is an abbreviation of a), returns false otherwise
(a string, b string)
| 24 | |
| 25 | // Returns true if it is possible to make a equals b (if b is an abbreviation of a), returns false otherwise |
| 26 | func Abbreviation(a string, b string) bool { |
| 27 | dp := make([][]bool, len(a)+1) |
| 28 | for i := range dp { |
| 29 | dp[i] = make([]bool, len(b)+1) |
| 30 | } |
| 31 | dp[0][0] = true |
| 32 | |
| 33 | for i := 0; i < len(a); i++ { |
| 34 | for j := 0; j <= len(b); j++ { |
| 35 | if dp[i][j] { |
| 36 | if j < len(b) && strings.ToUpper(string(a[i])) == string(b[j]) { |
| 37 | dp[i+1][j+1] = true |
| 38 | } |
| 39 | if string(a[i]) == strings.ToLower(string(a[i])) { |
| 40 | dp[i+1][j] = true |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return dp[len(a)][len(b)] |
| 47 | } |
no outgoing calls