leetcode#49 anagrams

Source: Internet
Author: User

Problem Definition:

Given an array of strings, return all groups of strings that is anagrams.

Note:all inputs'll is in lower-case.

Solution:

Requires that all existing anagram strings be placed in an array, and all returned results should look like this:

[' EMS ', ' MSE ', ' app ', ' PPA ' ...]

It is easy to achieve with hasptable.

1     #@param {string[]} STRs2     #@return {string[]}3     defanagrams (STRs):4         ifLen (STRs) <=1:5             return []6bigdix={}7          forAStrinchSTRs:8key=Str (sorted (ASTR))9             ifKey not inchBigdix:Tenbigdix[key]=[ASTR] One             Else: Abigdix[key]+=AStr, -res=[] -          forArrinchbigdix.values (): the             ifLen (arr) >1: -res+=arr -         returnRes -         

It is important to note that the dict in Python cannot guarantee the order of key. ordereddict is saved key-values in the order in which it is inserted, and it can also be used to generate a dictionary sorted by some sort of rule.

leetcode#49 anagrams

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.