Backtracking, Easy
Quesion
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create.
|
|
Note:
S
will be a string with length at most12
.S
will consist only of letters or digits.
My Answer
|
|
Running time: 10ms
Better Answer:
Be careful to check whether a character is a digit or a letter(lower case or upper case).BFS Solution:
|
|
DFS Solution:
|
|
String to char[]
char[] array= str.toCharArray();
|
|
Char[] to String
String str = new String(ch);
String str2 = String.valueOf(ch);
|
|
String to ArrayList
|
|
ASCII
|
|
Breath-First-Search
Use Queue~
|
|
boolean add(E e): This method adds the specified element at the end of Queue. Returns true if the the element is added successfully or false if the element is not added that basically happens when the Queue is at its max capacity and cannot take any more elements.
E element(): This method returns the head (the first element) of the Queue.
boolean offer(object): This is same as add() method.
E remove(): This method removes the head(first element) of the Queue and returns its value.
E poll(): This method is almost same as remove() method. The only difference between poll() and remove() is that poll() method returns null if the Queue is empty.
E peek(): This method is almost same as element() method. The only difference between peek() and element() is that peek() method returns null if the Queue is empty.
Depth-First-Search
Use Stack~