-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
57 lines (55 loc) · 1.32 KB
/
Copy pathtest.cpp
File metadata and controls
57 lines (55 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
public:
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>> res;
queue<TreeNode*> q;
queue<TreeNode*> nextq;
vector<int> temp;
TreeNode* curr = root;
q.push(curr);
while(!q.empty()){
curr = q.front();
temp.push_back(curr->val);
q.pop();
if(curr->left!=NULL) nextq.push(curr->left);
if(curr->right!=NULL) nextq.push(curr->right);
if(q.empty()){
res.push_back(temp);
temp.clear();
q.swap(nextq);
}
}
return res;
}
};
int main()
{
int t;
cin>>t;
while(t--){
int n, ans=0;
string s;
cin>>n>>s;
for(int i=0; i<n-1; i++){
for(int j=i+1; j<n; j++){
if(s[i]==s[j]){
int l=i, m=j, cnt=0;
while(s[l]==s[m]){
l++; m++;
cnt++;
}
ans = max(ans, cnt);
}
}
}
cout<<ans<<endl;
}
}