bicepjai
BAN USERprogramming, puzzles, exercise, dance, math and physics is all i need for survival
- 1of 1 vote
AnswersGiven a BST, maximum and minimum value, find the sum of nodes with values between the above range
- bicepjai in United States for Google Engineering| Report Duplicate | Flag | PURGE
Google Site Reliability Engineer Algorithm - 0of 0 votes
AnswersWrite an algorithm to find the ‘next’ node (e.g., in-order successor) of a given node in a binary search tree where each node has a link to its parent.
- bicepjai in United States for Google Engineering| Report Duplicate | Flag | PURGE
Google Site Reliability Engineer Algorithm
- 1 Answer finding maximum depth in BST
can this be solved this way ?
- bicepjai September 26, 2012
int maxDepth(struct node* node)
{
if (node==NULL)
return 0;
else
{
/* compute the depth of each subtree */
int lDepth = 1 + maxDepth(node->left);
int rDepth = 1 + maxDepth(node->right);
if (lDepth > rDepth)
return(lDepth);
else return(rDepth);
}
}| Flag | PURGE
Declaring the constructor private will ensure that no one outside of the class can directly instantiate the class. In this case, the only way to create an instance of the class is by providing a static public method, as is done when using the Factory Method Pattern.
Additionally, because the constructor is private, the class also cannot be inherited.
public static ArrayList<String> getPerms(String s) {
ArrayList<String> permutations = new ArrayList<String>();
if (s == null) { // error case
return null;
} else if (s.length() == 0) { // base case
permutations.add(“”);
return permutations;
}
char first = s.charAt(0); // get the first character
String remainder = s.substring(1); // remove the first character
ArrayList<String> words = getPerms(remainder);
for (String word : words) {
for (int j = 0; j <= word.length(); j++) {
permutations.add(insertCharAt(word, first, j));
}
}
return permutations;
}
public static String insertCharAt(String word, char c, int i) {
String start = word.substring(0, i);
String end = word.substring(i);
return start + c + end;
}
can anyone explain
- bicepjai September 26, 2012blog.csdn.net/maqingli20/article/details/7361057