From bca66cada0ebee4979f0110f87704ce4461b0a8e Mon Sep 17 00:00:00 2001 From: tanya-0708 Date: Sun, 4 Oct 2020 19:21:41 +0530 Subject: [PATCH] Added solution to Letter Combinations of a Phone Number in a leetcode folder --- .../Letter Combinations of a Phone Number.txt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 leetcode/cpp/backtracking/Letter Combinations of a Phone Number.txt diff --git a/leetcode/cpp/backtracking/Letter Combinations of a Phone Number.txt b/leetcode/cpp/backtracking/Letter Combinations of a Phone Number.txt new file mode 100644 index 00000000..7feaca67 --- /dev/null +++ b/leetcode/cpp/backtracking/Letter Combinations of a Phone Number.txt @@ -0,0 +1,28 @@ +class Solution { +public: + + + + vector letterCombinations(string digits) { + vector t{"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; + vector ans; + if(digits.length()==0) + return {}; + findans(t,ans,digits,""); + return ans; + + } +void findans(vector& t,vector& ans,string s,string path) +{ + if(s.length()==0) + { ans.push_back(path); + return; + } + + string temp=t[s[0]-'2']; + for(int i=0;i