CozILovYou
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Java
public boolean isUnivalTree (TreeNode root)
{
int value = root.children.isEmpty() ? root.val : root.children.get(0).val;
boolean result = true;
if (root==null) return false;
for (TreeNode node : root.children)
{
result = result & (node.val==value) & isUnivalTree(node);
}
return result;
}
Comment hidden because of low score. Click to expand.
0
of 0 vote
public static void findWordsByPattern (String[] inputStrings, String pattern)
{
String regex = pattern.replace("*", ".*");
for (String s: inputStrings)
{
if (Pattern.matches(regex, s))
{
System.out.println(s);
}
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Java
- CozILovYou April 06, 2018