Skip to content
Prev Previous commit
Next Next commit
Update Solution.java
  • Loading branch information
javadev authored Jun 12, 2022
commit 092f0461d364b733733f84b734bbe2cfbee283b4
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ public class Solution {
static class TreeNode {
int start;
int end;

char leftChar;
int leftCharLen;

char rightChar;
int rightCharLen;

int max;

TreeNode left;
TreeNode right;

Expand All @@ -32,11 +28,11 @@ public int[] longestRepeating(String s, String queryCharacters, int[] queryIndic
char[] qChar = queryCharacters.toCharArray();
TreeNode root = buildTree(sChar, 0, sChar.length - 1);
int[] result = new int[qChar.length];

for (int i = 0; i < qChar.length; i++) {
updateTree(root, queryIndices[i], qChar[i]);
assert root != null;
result[i] = root.max;
if (root != null) {
result[i] = root.max;
}
}
return result;
}
Expand All @@ -52,12 +48,9 @@ private TreeNode buildTree(char[] s, int from, int to) {
root.leftCharLen = root.rightCharLen = 1;
return root;
}

int middle = from + (to - from) / 2;

root.left = buildTree(s, from, middle);
root.right = buildTree(s, middle + 1, to);

updateNode(root);
return root;
}
Expand All @@ -72,7 +65,6 @@ private void updateTree(TreeNode root, int index, char c) {
}
updateTree(root.left, index, c);
updateTree(root.right, index, c);

updateNode(root);
}

Expand Down