QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#874345 | #3445. Numbers On a Tree | fernandes_queila | WA | 85ms | 48024kb | Java21 | 1.7kb | 2025-01-28 02:48:12 | 2025-01-28 02:48:13 |
Judging History
answer
import java.util.Scanner;
public class BinaryTreeLabel {
static class TreeNode {
int label;
TreeNode left, right;
TreeNode(int label) {
this.label = label;
this.left = this.right = null;
}
}
public static TreeNode buildTree(int height) {
int[] currentLabel = {1};
return buildTreeRecursively(height, currentLabel);
}
private static TreeNode buildTreeRecursively(int height, int[] currentLabel) {
if (height < 0) {
return null;
}
TreeNode rightChild = buildTreeRecursively(height - 1, currentLabel);
TreeNode leftChild = buildTreeRecursively(height - 1, currentLabel);
TreeNode node = new TreeNode(currentLabel[0]);
currentLabel[0]++;
node.left = leftChild;
node.right = rightChild;
return node;
}
public static int findLabel(TreeNode root, String path) {
TreeNode currentNode = root;
for (int i = 0; i < path.length(); i++) {
if (path.charAt(i) == 'L') {
currentNode = currentNode.left;
} else if (path.charAt(i) == 'R') {
currentNode = currentNode.right;
}
}
return currentNode.label;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String inputLine = scanner.nextLine().strip();
String[] parts = inputLine.split(" ");
int height = Integer.parseInt(parts[0]);
String path = parts.length > 1 ? parts[1] : "";
TreeNode root = buildTree(height);
int result = findLabel(root, path);
System.out.println(result);
scanner.close();
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 85ms
memory: 48024kb
input:
3 LR
output:
10
result:
wrong answer 1st lines differ - expected: '11', found: '10'