@@ -0,0 +1,1769 @@
+class Solution:%0A    # @param strs: A list of strings%0A    # @return: A list of strings%0A%0A    #TLE%0A    # def anagrams(self, strs):%0A    #     # write your code here%0A    #     if len(strs) %3C= 1:%0A    #         return strs%0A    #     final_res = %5B%5D%0A    #     for i in xrange(len(strs)):%0A    #         for j in xrange(i):%0A    #             if i != j:%0A    #                 if self.anagram(strs%5Bi%5D, strs%5Bj%5D) == True:%0A    #                         final_res.append(strs%5Bi%5D)%0A    #                         final_res.append(strs%5Bj%5D)%0A%0A    #     final_res = list(set(final_res))%0A    #     real_final_res = %5B%5D%0A    #     for item in strs:%0A    #         if item in final_res:%0A    #             real_final_res.append(item)%0A    #     return real_final_res%0A%0A%0A%0A    # def anagram(self, s, t):%0A    #     list_s = list(s)%0A    #     list_t = list(t)%0A    #     for item in list_s:%0A    #         try:%0A    #             list_t.remove(item)%0A    #         except:%0A    #             return False%0A    #     if len(list_t) == 0:%0A    #         return True%0A    def anagrams(self, strs):%0A        ret = %5B%5D%0A        if strs == None:%0A            return ret%0A%0A        hmap = %7B%7D%0A        len_ = len(strs)%0A        for i in xrange(len_):%0A            s = strs%5Bi%5D%0A%0A            chars = list(s)%0A            strSort = %22%22.join(sorted(chars))%0A%0A            if strSort not in hmap:%0A                new_list = %5B%5D%0A                hmap%5BstrSort%5D = new_list%0A            hmap.get(strSort).append(s)%0A        final_res = %5B%5D%0A        for item in hmap.values():%0A            if len(item) == 1:%0A                continue%0A            %0A            final_res += item%0A        return final_res%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0Aa = Solution()%0Aprint a.anagrams(%5B%22%22,'b',%22%22%5D)%0Aprint a.anagrams(%5B%22tea%22,%22and%22,%22ate%22,%22eat%22,%22den%22%5D)%0Aprint a.anagrams(%5B%22tea%22,%22%22,%22eat%22,%22%22,%22tea%22,%22%22%5D)

add new