Home > Back-end >  About the string index cross-border problems, solving!!!!!!!!!!
About the string index cross-border problems, solving!!!!!!!!!!

Time:11-27

Recently learned data structures, so do something LeetCode to this topic, topic as shown in the following



I took advantage of the hash table and the recursive function of the specific code below
 package middle; 

import java.util.ArrayList;
Import the Java. Util. Arrays;
Import the Java. Util. HashMap;
import java.util.List;
import java.util.Map;

Public class number combination {
Public static void main (String [] args) {
String STR="273";
List List=letterCombinations (STR);
System.out.println(list);
}

Public static List LetterCombinations (String) who {
List list=new ArrayList<> (a);
Map The map=new HashMap (a);
The map. The put (' 2 ', "ABC");
The map. The put (' 3 ', "def");
The map. The put (' 4 ', "ghi");
The map. The put (' 5 ', "JKL");
The map. The put (' 6 ', "mno");
Map. The put (' 7 ', "PQRS");
The map. The put (' 8 ', "tuv");
The map. The put (' 9 ', "wxyz");

Method (map, list, who, "");
return list;
}

/* *
*
* @ param map

* button mapping* @ param list
* the final list
* @ param s
* the current input numeric characters
* @ param result
* transfer characters, initial null character
*/
Public static void method (Map The map, List The list, the String s, String result) {
If (s=="") {
return;
}
String STR=map. Get (s.c harAt (0));
For (int I=0; i String result2=result + STR. CharAt (I);
If (s.l ength () & gt; 1) {
Method (map, list, s.s ubstring (1), result2);
} else if (s.l ength ()==1) {
List. The add (result2);
}
}
}
}

Testing examples can be passed, but submit prompt when I perform error, I don't know where is the specific error


For passing bosses spend little time to help me see, really appreciate!!!!!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

S=="", the writing has a problem, is not true, so have" "crossing the line when I was back, to s.e quase (" ")

CodePudding user response:

reference 1st floor icoolno1 response:
s=="", the writing has a problem, is not true, so have" "crossing the line when I was back, to s.e quase (" ")

Is this problem, thank you

CodePudding user response:

HHH, solved the good,
  • Related