Leetcode:letter combinations of a phone number keypad letter Map

Source: Internet
Author: User

Letter combinations of a Phone number:

Given a digit string, return all possible letter combinations, the number could represent.

A mapping of Digit to letters (just as on the telephone buttons) is given below.

Input:digitstring " at"Output: ["AD","AE","af","BD"," be","BF","CD","CE","CF"].

Problem Solving Analysis:

Deep search of violence

Using vector<string> to simulate a map is easier than using a map

classSolution { Public: Vector<string> Lettercombinations (stringdigits) {        Constvector<string> letter = {" ","","ABC","def","Ghi","JKL","MnO","PQRS","TUV","WXYZ"};//0,1,2 ...vector<string>result; DFS (letter, digits,0,"", result); returnresult; }        voidDfsConstvector<string>& Letter,string& Digits,intCurstring Path, vector<string>&result) {        if(cur = =digits.size ())            { result.push_back (path); return; }         for(Auto c:letter.at (digits.at (cur)-'0') {DFS (letter, digits, cur+1,path + c, result); }    }};

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.