From 224bc169f5a92482a394905db54169d7d817b720 Mon Sep 17 00:00:00 2001 From: ParthDholariya <92844674+Parth-Dholariya@users.noreply.github.com> Date: Wed, 9 Apr 2025 10:46:28 +0530 Subject: [PATCH 1/3] Update code for cpp in README_EN.md --- .../README_EN.md | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md index 1669f53620258..c83e20a2e8d33 100644 --- a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md +++ b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md @@ -114,6 +114,111 @@ tags: #### C++ ```cpp +class Solution { +public: + struct TrieNode { + int count = 0; + int depth = 0; + int children[26] = {0}; + }; + + class SegmentTree { + public: + int n; + vector tree; + vector& globalCount; + SegmentTree(int n, vector& globalCount) : n(n), globalCount(globalCount) { + tree.assign(4 * (n + 1), -1); + build(1, 1, n); + } + void build(int idx, int l, int r) { + if (l == r) { + tree[idx] = globalCount[l] > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + build(idx * 2, l, mid); + build(idx * 2 + 1, mid + 1, r); + tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]); + } + void update(int idx, int l, int r, int pos, int newVal) { + if (l == r) { + tree[idx] = newVal > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + if (pos <= mid) + update(idx * 2, l, mid, pos, newVal); + else + update(idx * 2 + 1, mid + 1, r, pos, newVal); + tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]); + } + int query() { + return tree[1]; + } + }; + + vector longestCommonPrefix(vector& words, int k) { + int n = words.size(); + vector ans(n, 0); + if (n - 1 < k) return ans; + vector trie(1); + for (const string& word : words) { + int cur = 0; + for (char c : word) { + int idx = c - 'a'; + if (trie[cur].children[idx] == 0) { + trie[cur].children[idx] = trie.size(); + trie.push_back({0, trie[cur].depth + 1}); + } + cur = trie[cur].children[idx]; + trie[cur].count++; + } + } + int maxDepth = 0; + for (int i = 1; i < trie.size(); ++i) { + if (trie[i].count >= k) { + maxDepth = max(maxDepth, trie[i].depth); + } + } + vector globalCount(maxDepth + 1, 0); + for (int i = 1; i < trie.size(); ++i) { + if (trie[i].count >= k && trie[i].depth <= maxDepth) { + globalCount[trie[i].depth]++; + } + } + vector> fragileList(n); + for (int i = 0; i < n; ++i) { + int cur = 0; + for (char c : words[i]) { + int idx = c - 'a'; + cur = trie[cur].children[idx]; + if (trie[cur].count == k) { + fragileList[i].push_back(trie[cur].depth); + } + } + } + int segSize = maxDepth; + if (segSize >= 1) { + SegmentTree segTree(segSize, globalCount); + for (int i = 0; i < n; ++i) { + if (n - 1 < k) { + ans[i] = 0; + } else { + for (int d : fragileList[i]) { + segTree.update(1, 1, segSize, d, globalCount[d] - 1); + } + int res = segTree.query(); + ans[i] = res == -1 ? 0 : res; + for (int d : fragileList[i]) { + segTree.update(1, 1, segSize, d, globalCount[d]); + } + } + } + } + return ans; + } +}; ``` From ccdbf2975656ae334c7475c1c5a19f792aa2e6dd Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Thu, 10 Apr 2025 06:33:36 +0800 Subject: [PATCH 2/3] Add Java and C++ solutions for problem 3485. --- .../README.md | 237 +++++++++++++++++- .../README_EN.md | 129 ++++++++++ .../Solution.cpp | 105 ++++++++ .../Solution.java | 130 ++++++++++ 4 files changed, 599 insertions(+), 2 deletions(-) create mode 100644 solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.cpp create mode 100644 solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.java diff --git a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README.md b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README.md index e7fc56d1e6e20..2e6416215d6f8 100644 --- a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README.md +++ b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README.md @@ -114,13 +114,246 @@ tags: #### Java ```java - +class Solution { + static class TrieNode { + int count = 0; + int depth = 0; + int[] children = new int[26]; + + TrieNode() { + for (int i = 0; i < 26; ++i) children[i] = -1; + } + } + + static class SegmentTree { + int n; + int[] tree; + int[] globalCount; + + SegmentTree(int n, int[] globalCount) { + this.n = n; + this.globalCount = globalCount; + this.tree = new int[4 * (n + 1)]; + for (int i = 0; i < tree.length; i++) tree[i] = -1; + build(1, 1, n); + } + + void build(int idx, int l, int r) { + if (l == r) { + tree[idx] = globalCount[l] > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + build(idx * 2, l, mid); + build(idx * 2 + 1, mid + 1, r); + tree[idx] = Math.max(tree[idx * 2], tree[idx * 2 + 1]); + } + + void update(int idx, int l, int r, int pos, int newVal) { + if (l == r) { + tree[idx] = newVal > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + if (pos <= mid) { + update(idx * 2, l, mid, pos, newVal); + } else { + update(idx * 2 + 1, mid + 1, r, pos, newVal); + } + tree[idx] = Math.max(tree[idx * 2], tree[idx * 2 + 1]); + } + + int query() { + return tree[1]; + } + } + + public int[] longestCommonPrefix(String[] words, int k) { + int n = words.length; + int[] ans = new int[n]; + if (n - 1 < k) return ans; + + ArrayList trie = new ArrayList<>(); + trie.add(new TrieNode()); + + for (String word : words) { + int cur = 0; + for (char c : word.toCharArray()) { + int idx = c - 'a'; + if (trie.get(cur).children[idx] == -1) { + trie.get(cur).children[idx] = trie.size(); + TrieNode node = new TrieNode(); + node.depth = trie.get(cur).depth + 1; + trie.add(node); + } + cur = trie.get(cur).children[idx]; + trie.get(cur).count++; + } + } + + int maxDepth = 0; + for (int i = 1; i < trie.size(); ++i) { + if (trie.get(i).count >= k) { + maxDepth = Math.max(maxDepth, trie.get(i).depth); + } + } + + int[] globalCount = new int[maxDepth + 1]; + for (int i = 1; i < trie.size(); ++i) { + TrieNode node = trie.get(i); + if (node.count >= k && node.depth <= maxDepth) { + globalCount[node.depth]++; + } + } + + List> fragileList = new ArrayList<>(); + for (int i = 0; i < n; ++i) { + fragileList.add(new ArrayList<>()); + } + + for (int i = 0; i < n; ++i) { + int cur = 0; + for (char c : words[i].toCharArray()) { + int idx = c - 'a'; + cur = trie.get(cur).children[idx]; + if (trie.get(cur).count == k) { + fragileList.get(i).add(trie.get(cur).depth); + } + } + } + + int segSize = maxDepth; + if (segSize >= 1) { + SegmentTree segTree = new SegmentTree(segSize, globalCount); + for (int i = 0; i < n; ++i) { + if (n - 1 < k) { + ans[i] = 0; + } else { + for (int d : fragileList.get(i)) { + segTree.update(1, 1, segSize, d, globalCount[d] - 1); + } + int res = segTree.query(); + ans[i] = res == -1 ? 0 : res; + for (int d : fragileList.get(i)) { + segTree.update(1, 1, segSize, d, globalCount[d]); + } + } + } + } + + return ans; + } +} ``` #### C++ ```cpp - +class Solution { +public: + struct TrieNode { + int count = 0; + int depth = 0; + int children[26] = {0}; + }; + + class SegmentTree { + public: + int n; + vector tree; + vector& globalCount; + SegmentTree(int n, vector& globalCount) : n(n), globalCount(globalCount) { + tree.assign(4 * (n + 1), -1); + build(1, 1, n); + } + void build(int idx, int l, int r) { + if (l == r) { + tree[idx] = globalCount[l] > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + build(idx * 2, l, mid); + build(idx * 2 + 1, mid + 1, r); + tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]); + } + void update(int idx, int l, int r, int pos, int newVal) { + if (l == r) { + tree[idx] = newVal > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + if (pos <= mid) + update(idx * 2, l, mid, pos, newVal); + else + update(idx * 2 + 1, mid + 1, r, pos, newVal); + tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]); + } + int query() { + return tree[1]; + } + }; + + vector longestCommonPrefix(vector& words, int k) { + int n = words.size(); + vector ans(n, 0); + if (n - 1 < k) return ans; + vector trie(1); + for (const string& word : words) { + int cur = 0; + for (char c : word) { + int idx = c - 'a'; + if (trie[cur].children[idx] == 0) { + trie[cur].children[idx] = trie.size(); + trie.push_back({0, trie[cur].depth + 1}); + } + cur = trie[cur].children[idx]; + trie[cur].count++; + } + } + int maxDepth = 0; + for (int i = 1; i < trie.size(); ++i) { + if (trie[i].count >= k) { + maxDepth = max(maxDepth, trie[i].depth); + } + } + vector globalCount(maxDepth + 1, 0); + for (int i = 1; i < trie.size(); ++i) { + if (trie[i].count >= k && trie[i].depth <= maxDepth) { + globalCount[trie[i].depth]++; + } + } + vector> fragileList(n); + for (int i = 0; i < n; ++i) { + int cur = 0; + for (char c : words[i]) { + int idx = c - 'a'; + cur = trie[cur].children[idx]; + if (trie[cur].count == k) { + fragileList[i].push_back(trie[cur].depth); + } + } + } + int segSize = maxDepth; + if (segSize >= 1) { + SegmentTree segTree(segSize, globalCount); + for (int i = 0; i < n; ++i) { + if (n - 1 < k) { + ans[i] = 0; + } else { + for (int d : fragileList[i]) { + segTree.update(1, 1, segSize, d, globalCount[d] - 1); + } + int res = segTree.query(); + ans[i] = res == -1 ? 0 : res; + for (int d : fragileList[i]) { + segTree.update(1, 1, segSize, d, globalCount[d]); + } + } + } + } + return ans; + } +}; ``` #### Go diff --git a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md index c83e20a2e8d33..53eae9a891b57 100644 --- a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md +++ b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md @@ -108,7 +108,136 @@ tags: #### Java ```java +class Solution { + static class TrieNode { + int count = 0; + int depth = 0; + int[] children = new int[26]; + + TrieNode() { + for (int i = 0; i < 26; ++i) children[i] = -1; + } + } + + static class SegmentTree { + int n; + int[] tree; + int[] globalCount; + + SegmentTree(int n, int[] globalCount) { + this.n = n; + this.globalCount = globalCount; + this.tree = new int[4 * (n + 1)]; + for (int i = 0; i < tree.length; i++) tree[i] = -1; + build(1, 1, n); + } + + void build(int idx, int l, int r) { + if (l == r) { + tree[idx] = globalCount[l] > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + build(idx * 2, l, mid); + build(idx * 2 + 1, mid + 1, r); + tree[idx] = Math.max(tree[idx * 2], tree[idx * 2 + 1]); + } + + void update(int idx, int l, int r, int pos, int newVal) { + if (l == r) { + tree[idx] = newVal > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + if (pos <= mid) { + update(idx * 2, l, mid, pos, newVal); + } else { + update(idx * 2 + 1, mid + 1, r, pos, newVal); + } + tree[idx] = Math.max(tree[idx * 2], tree[idx * 2 + 1]); + } + + int query() { + return tree[1]; + } + } + + public int[] longestCommonPrefix(String[] words, int k) { + int n = words.length; + int[] ans = new int[n]; + if (n - 1 < k) return ans; + + ArrayList trie = new ArrayList<>(); + trie.add(new TrieNode()); + + for (String word : words) { + int cur = 0; + for (char c : word.toCharArray()) { + int idx = c - 'a'; + if (trie.get(cur).children[idx] == -1) { + trie.get(cur).children[idx] = trie.size(); + TrieNode node = new TrieNode(); + node.depth = trie.get(cur).depth + 1; + trie.add(node); + } + cur = trie.get(cur).children[idx]; + trie.get(cur).count++; + } + } + int maxDepth = 0; + for (int i = 1; i < trie.size(); ++i) { + if (trie.get(i).count >= k) { + maxDepth = Math.max(maxDepth, trie.get(i).depth); + } + } + + int[] globalCount = new int[maxDepth + 1]; + for (int i = 1; i < trie.size(); ++i) { + TrieNode node = trie.get(i); + if (node.count >= k && node.depth <= maxDepth) { + globalCount[node.depth]++; + } + } + + List> fragileList = new ArrayList<>(); + for (int i = 0; i < n; ++i) { + fragileList.add(new ArrayList<>()); + } + + for (int i = 0; i < n; ++i) { + int cur = 0; + for (char c : words[i].toCharArray()) { + int idx = c - 'a'; + cur = trie.get(cur).children[idx]; + if (trie.get(cur).count == k) { + fragileList.get(i).add(trie.get(cur).depth); + } + } + } + + int segSize = maxDepth; + if (segSize >= 1) { + SegmentTree segTree = new SegmentTree(segSize, globalCount); + for (int i = 0; i < n; ++i) { + if (n - 1 < k) { + ans[i] = 0; + } else { + for (int d : fragileList.get(i)) { + segTree.update(1, 1, segSize, d, globalCount[d] - 1); + } + int res = segTree.query(); + ans[i] = res == -1 ? 0 : res; + for (int d : fragileList.get(i)) { + segTree.update(1, 1, segSize, d, globalCount[d]); + } + } + } + } + + return ans; + } +} ``` #### C++ diff --git a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.cpp b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.cpp new file mode 100644 index 0000000000000..692a93755d2d6 --- /dev/null +++ b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.cpp @@ -0,0 +1,105 @@ +class Solution { +public: + struct TrieNode { + int count = 0; + int depth = 0; + int children[26] = {0}; + }; + + class SegmentTree { + public: + int n; + vector tree; + vector& globalCount; + SegmentTree(int n, vector& globalCount) : n(n), globalCount(globalCount) { + tree.assign(4 * (n + 1), -1); + build(1, 1, n); + } + void build(int idx, int l, int r) { + if (l == r) { + tree[idx] = globalCount[l] > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + build(idx * 2, l, mid); + build(idx * 2 + 1, mid + 1, r); + tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]); + } + void update(int idx, int l, int r, int pos, int newVal) { + if (l == r) { + tree[idx] = newVal > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + if (pos <= mid) + update(idx * 2, l, mid, pos, newVal); + else + update(idx * 2 + 1, mid + 1, r, pos, newVal); + tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]); + } + int query() { + return tree[1]; + } + }; + + vector longestCommonPrefix(vector& words, int k) { + int n = words.size(); + vector ans(n, 0); + if (n - 1 < k) return ans; + vector trie(1); + for (const string& word : words) { + int cur = 0; + for (char c : word) { + int idx = c - 'a'; + if (trie[cur].children[idx] == 0) { + trie[cur].children[idx] = trie.size(); + trie.push_back({0, trie[cur].depth + 1}); + } + cur = trie[cur].children[idx]; + trie[cur].count++; + } + } + int maxDepth = 0; + for (int i = 1; i < trie.size(); ++i) { + if (trie[i].count >= k) { + maxDepth = max(maxDepth, trie[i].depth); + } + } + vector globalCount(maxDepth + 1, 0); + for (int i = 1; i < trie.size(); ++i) { + if (trie[i].count >= k && trie[i].depth <= maxDepth) { + globalCount[trie[i].depth]++; + } + } + vector> fragileList(n); + for (int i = 0; i < n; ++i) { + int cur = 0; + for (char c : words[i]) { + int idx = c - 'a'; + cur = trie[cur].children[idx]; + if (trie[cur].count == k) { + fragileList[i].push_back(trie[cur].depth); + } + } + } + int segSize = maxDepth; + if (segSize >= 1) { + SegmentTree segTree(segSize, globalCount); + for (int i = 0; i < n; ++i) { + if (n - 1 < k) { + ans[i] = 0; + } else { + for (int d : fragileList[i]) { + segTree.update(1, 1, segSize, d, globalCount[d] - 1); + } + int res = segTree.query(); + ans[i] = res == -1 ? 0 : res; + for (int d : fragileList[i]) { + segTree.update(1, 1, segSize, d, globalCount[d]); + } + } + } + } + return ans; + } +}; \ No newline at end of file diff --git a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.java b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.java new file mode 100644 index 0000000000000..6b158681eca70 --- /dev/null +++ b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.java @@ -0,0 +1,130 @@ +class Solution { + static class TrieNode { + int count = 0; + int depth = 0; + int[] children = new int[26]; + + TrieNode() { + for (int i = 0; i < 26; ++i) children[i] = -1; + } + } + + static class SegmentTree { + int n; + int[] tree; + int[] globalCount; + + SegmentTree(int n, int[] globalCount) { + this.n = n; + this.globalCount = globalCount; + this.tree = new int[4 * (n + 1)]; + for (int i = 0; i < tree.length; i++) tree[i] = -1; + build(1, 1, n); + } + + void build(int idx, int l, int r) { + if (l == r) { + tree[idx] = globalCount[l] > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + build(idx * 2, l, mid); + build(idx * 2 + 1, mid + 1, r); + tree[idx] = Math.max(tree[idx * 2], tree[idx * 2 + 1]); + } + + void update(int idx, int l, int r, int pos, int newVal) { + if (l == r) { + tree[idx] = newVal > 0 ? l : -1; + return; + } + int mid = (l + r) / 2; + if (pos <= mid) { + update(idx * 2, l, mid, pos, newVal); + } else { + update(idx * 2 + 1, mid + 1, r, pos, newVal); + } + tree[idx] = Math.max(tree[idx * 2], tree[idx * 2 + 1]); + } + + int query() { + return tree[1]; + } + } + + public int[] longestCommonPrefix(String[] words, int k) { + int n = words.length; + int[] ans = new int[n]; + if (n - 1 < k) return ans; + + ArrayList trie = new ArrayList<>(); + trie.add(new TrieNode()); + + for (String word : words) { + int cur = 0; + for (char c : word.toCharArray()) { + int idx = c - 'a'; + if (trie.get(cur).children[idx] == -1) { + trie.get(cur).children[idx] = trie.size(); + TrieNode node = new TrieNode(); + node.depth = trie.get(cur).depth + 1; + trie.add(node); + } + cur = trie.get(cur).children[idx]; + trie.get(cur).count++; + } + } + + int maxDepth = 0; + for (int i = 1; i < trie.size(); ++i) { + if (trie.get(i).count >= k) { + maxDepth = Math.max(maxDepth, trie.get(i).depth); + } + } + + int[] globalCount = new int[maxDepth + 1]; + for (int i = 1; i < trie.size(); ++i) { + TrieNode node = trie.get(i); + if (node.count >= k && node.depth <= maxDepth) { + globalCount[node.depth]++; + } + } + + List> fragileList = new ArrayList<>(); + for (int i = 0; i < n; ++i) { + fragileList.add(new ArrayList<>()); + } + + for (int i = 0; i < n; ++i) { + int cur = 0; + for (char c : words[i].toCharArray()) { + int idx = c - 'a'; + cur = trie.get(cur).children[idx]; + if (trie.get(cur).count == k) { + fragileList.get(i).add(trie.get(cur).depth); + } + } + } + + int segSize = maxDepth; + if (segSize >= 1) { + SegmentTree segTree = new SegmentTree(segSize, globalCount); + for (int i = 0; i < n; ++i) { + if (n - 1 < k) { + ans[i] = 0; + } else { + for (int d : fragileList.get(i)) { + segTree.update(1, 1, segSize, d, globalCount[d] - 1); + } + int res = segTree.query(); + ans[i] = res == -1 ? 0 : res; + for (int d : fragileList.get(i)) { + segTree.update(1, 1, segSize, d, globalCount[d]); + } + } + } + } + + return ans; + } +} \ No newline at end of file From 3a7f3323dda28a18b512a7b30825250189bd1042 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Thu, 10 Apr 2025 06:36:33 +0800 Subject: [PATCH 3/3] Format SegmentTree constructor initialization list --- .../README.md | 4 +++- .../README_EN.md | 5 +++-- .../Solution.cpp | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README.md b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README.md index 2e6416215d6f8..1cc9dda7c9806 100644 --- a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README.md +++ b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README.md @@ -262,7 +262,9 @@ public: int n; vector tree; vector& globalCount; - SegmentTree(int n, vector& globalCount) : n(n), globalCount(globalCount) { + SegmentTree(int n, vector& globalCount) + : n(n) + , globalCount(globalCount) { tree.assign(4 * (n + 1), -1); build(1, 1, n); } diff --git a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md index 53eae9a891b57..e2f26d7aba3ae 100644 --- a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md +++ b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/README_EN.md @@ -256,7 +256,9 @@ public: int n; vector tree; vector& globalCount; - SegmentTree(int n, vector& globalCount) : n(n), globalCount(globalCount) { + SegmentTree(int n, vector& globalCount) + : n(n) + , globalCount(globalCount) { tree.assign(4 * (n + 1), -1); build(1, 1, n); } @@ -348,7 +350,6 @@ public: return ans; } }; - ``` #### Go diff --git a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.cpp b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.cpp index 692a93755d2d6..fa4ada62e21a0 100644 --- a/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.cpp +++ b/solution/3400-3499/3485.Longest Common Prefix of K Strings After Removal/Solution.cpp @@ -11,7 +11,9 @@ class Solution { int n; vector tree; vector& globalCount; - SegmentTree(int n, vector& globalCount) : n(n), globalCount(globalCount) { + SegmentTree(int n, vector& globalCount) + : n(n) + , globalCount(globalCount) { tree.assign(4 * (n + 1), -1); build(1, 1, n); }