"class Node
{
int val;
Node left, right;
Node(int v)
{
val = v;
left = right = null;
}
}
class BinaryTree
{
Node root1, root2;
boolean identicalTrees(Node a, Node b)
{
if (a == null && b == null)
return true;
if (a != null && b != null)
return (a.val == b.val
&& identicalTrees(a.left, b.left)
&& identicalTrees(a.right, b.right));
"
Tushar A. - "class Node
{
int val;
Node left, right;
Node(int v)
{
val = v;
left = right = null;
}
}
class BinaryTree
{
Node root1, root2;
boolean identicalTrees(Node a, Node b)
{
if (a == null && b == null)
return true;
if (a != null && b != null)
return (a.val == b.val
&& identicalTrees(a.left, b.left)
&& identicalTrees(a.right, b.right));
"See full answer
"let str = 'this is a test of programs';
let obj={};
for (let s of str )
obj[s]?(obj[s]=obj[s]+1):(obj[s]=1)
console.log(JSON.stringify(obj))"
Anonymous Emu - "let str = 'this is a test of programs';
let obj={};
for (let s of str )
obj[s]?(obj[s]=obj[s]+1):(obj[s]=1)
console.log(JSON.stringify(obj))"See full answer
Software Engineer
Coding
+2 more
🧠Want an expert answer to a question? Saving questions lets us know what content to make next.
"function constructTree(n, matrix) {
let parent = [];
let child = [];
let root = null;
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (matrixi === 1) {
parent.push(i);
child.push(j);
}
}
}
for (let i = 0; i < n; i++) {
if (parent.indexOf(i) === -1) {
root = i;
}
}
let node = new Node(root);
for (let i = 0; i < n; i++) {
if (i !== root) {
constructTreeUtil(node, parent[i], child[i]);
}
}
return node;
}"
Ugo C. - "function constructTree(n, matrix) {
let parent = [];
let child = [];
let root = null;
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (matrixi === 1) {
parent.push(i);
child.push(j);
}
}
}
for (let i = 0; i < n; i++) {
if (parent.indexOf(i) === -1) {
root = i;
}
}
let node = new Node(root);
for (let i = 0; i < n; i++) {
if (i !== root) {
constructTreeUtil(node, parent[i], child[i]);
}
}
return node;
}"See full answer
"import java.util.Arrays;
import java.util.stream.Collectors;
class Main
{
// Recursive function to print all combinations of numbers from \i\ to \n\
// having sum \n. The index\ denotes the next free slot in the output array \out\
public static void printCombinations(int i, int n, int[] out, int index)
{
// if the sum becomes n, print the combination
if (n == 0)
{
System.out.println(Arrays.stream(out).limit(index)
.boxed().collect(Collectors.toList()));
}
// start from the previous e"
Relynn may silver B. - "import java.util.Arrays;
import java.util.stream.Collectors;
class Main
{
// Recursive function to print all combinations of numbers from \i\ to \n\
// having sum \n. The index\ denotes the next free slot in the output array \out\
public static void printCombinations(int i, int n, int[] out, int index)
{
// if the sum becomes n, print the combination
if (n == 0)
{
System.out.println(Arrays.stream(out).limit(index)
.boxed().collect(Collectors.toList()));
}
// start from the previous e"See full answer
"The height of a binary tree is the maximum number of edges from the root node to any leaf node. To calculate the height of a binary tree, we can use a recursive approach. The basic idea is to compare the heights of the left and right subtrees of the root node, and return the maximum of them plus one."
Prashant Y. - "The height of a binary tree is the maximum number of edges from the root node to any leaf node. To calculate the height of a binary tree, we can use a recursive approach. The basic idea is to compare the heights of the left and right subtrees of the root node, and return the maximum of them plus one."See full answer
"String commonStr(String str1, String str2) {
int len1 = str1.length();
int len2 = str2.length();
if (len1 == 0 || len2 == 0) return "";
// let dpx reprsent the longest common str of 0...x
int dp = new int len1 + 1;
int maxLen = 0;
int endIndex = 0;
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
if (str1.charAt(i-1) == str2.charAt(j-1)) {
dpi = dpi-1 + 1;
"
Emma X. - "String commonStr(String str1, String str2) {
int len1 = str1.length();
int len2 = str2.length();
if (len1 == 0 || len2 == 0) return "";
// let dpx reprsent the longest common str of 0...x
int dp = new int len1 + 1;
int maxLen = 0;
int endIndex = 0;
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
if (str1.charAt(i-1) == str2.charAt(j-1)) {
dpi = dpi-1 + 1;
"See full answer