✅ arrays addition

public class Solution {
public IList<string> LetterCombinations(string digits) {
Dictionary<char, char[]> phone = new Dictionary<char,char[]>(){
{'2', new char[]{'a','b','c'}},
{'3',new char[]{'d','e','f'}},
{'4',new char[]{'g','h','i'}},
{'5',new char[]{'j','k','l'}},
{'6',new char[]{'m','n','o'}},
{'7',new char[]{'p','q','r','s'}},
{'8',new char[]{'t','u','v'}},
{'9',new char[]{'w','x','y','z'}}};

List<string> combinations = new List<string>();
int length = digits.Length;
if(digits == null || length == 0) return combinations;
for(int i = 0; i < length; i++){
if(length == 1){
foreach (var letter in phone[digits[i]])
{
combinations.Add(letter.ToString());
}
}
for(int k = 0 ; k < length - 1; k++){

for(int j = 0 + k; j < length - 1; j++){
int z = 0;
combinations.add( phone[digits[k][z]] += phone[digits[j][z]]);
z++
if(z == 2) break;
}
}



}
return combinations;
}
}
public class Solution {
public IList<string> LetterCombinations(string digits) {
Dictionary<char, char[]> phone = new Dictionary<char,char[]>(){
{'2', new char[]{'a','b','c'}},
{'3',new char[]{'d','e','f'}},
{'4',new char[]{'g','h','i'}},
{'5',new char[]{'j','k','l'}},
{'6',new char[]{'m','n','o'}},
{'7',new char[]{'p','q','r','s'}},
{'8',new char[]{'t','u','v'}},
{'9',new char[]{'w','x','y','z'}}};

List<string> combinations = new List<string>();
int length = digits.Length;
if(digits == null || length == 0) return combinations;
for(int i = 0; i < length; i++){
if(length == 1){
foreach (var letter in phone[digits[i]])
{
combinations.Add(letter.ToString());
}
}
for(int k = 0 ; k < length - 1; k++){

for(int j = 0 + k; j < length - 1; j++){
int z = 0;
combinations.add( phone[digits[k][z]] += phone[digits[j][z]]);
z++
if(z == 2) break;
}
}



}
return combinations;
}
}
so this is a code I wrote for leet code ik code could be done better but can someone help me at the very bottom of this code error is that I simply cannot add chars from different arrays can someone help me with that
6 Replies
Angius
Angius2mo ago
What exactly is the error?
tatoie dardmeladze
Cannot apply indexing with [] to an expression of type 'char'
Angius
Angius2mo ago
Yeah digits is a string digits[k] would be kth char in that string What would be digits[k][z]?
tatoie dardmeladze
okay so in dictionary there is a phone and yea digits is string like "23" and then phone[digits[k]] is the which key to acces this is a key of chars array from up in dictionary so from this you getting z th element but problem is when I try to grab those I ca do it without any strugle but problem is that I simply cannot add those two to each other
Angius
Angius2mo ago
So you want phone[digits[k]][z] then
tatoie dardmeladze
ohh it might work I amma let you know