Leetcode: Day 131, #288 #289 #293 #294 Unique Word Abbreviation, Game of Life, Flip Game, Flip Game II
Tuesday, October 27, 2015 Day 131, #288 #289 #293 #294 Unique Word Abbreviation, Game of Life, Flip Game, Flip Game II Unique Word Abbreviation An abbreviation of a word follows the form
. 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 --> i18n 1 1---5----0 d) l|ocalizatio|n --> l10n Assume you have a dictionary and given a word, find whether its abbreviation is unique in the dictionary. A word's abbreviation is unique if no other word from the dictionary has the same abbreviation. Example: false isUnique("cart") -> true isUnique("cane") -> false isUnique("make") -> true class ValidWordAbbr { public: string getAbre(string s) { int len = s.length(); if (len > 1) { s = s[0] + to_string(len - 2) + s[len - 1]; } return s; } ValidWordAbbr(vector &dictionary) { for (int i = 0; i < dictionary.
Read full article from Leetcode: Day 131, #288 #289 #293 #294 Unique Word Abbreviation, Game of Life, Flip Game, Flip Game II
No comments:
Post a Comment