Skip to content

Commit 8f72415

Browse files
committed
Committed
1 parent 80d51cb commit 8f72415

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define print(a) cout << a << endl
5+
6+
int main(){
7+
int n,c;
8+
cin >> n >> c;
9+
10+
(c == 0) ? print(1) : (c<=n/2) ? print(c) : print(n%c) ;
11+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define print(a) cout << a << endl
5+
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
6+
7+
const int N = 1e5 + 10;
8+
9+
int cnt[N],f[N];
10+
11+
int main(){
12+
__;
13+
int n;
14+
cin >> n;
15+
16+
int mx = 0;
17+
int ans;
18+
19+
for(int i=1;i<=n;i++){
20+
int color;
21+
cin >> color;
22+
23+
cnt[f[color]]--;
24+
f[color]++;
25+
cnt[f[color]]++;
26+
27+
mx = max(mx,f[color]);
28+
29+
bool ok = false;
30+
31+
if(cnt[i] == 1)
32+
ok = true;
33+
else if(cnt[1] == i)
34+
ok = true;
35+
else if(cnt[mx]*mx == i-1 && cnt[1] == 1)
36+
ok = true;
37+
else if(cnt[mx-1]*(mx-1) == i-mx && cnt[mx] == 1)
38+
ok = true;
39+
40+
if(ok)
41+
ans = i;
42+
}
43+
44+
print(ans);
45+
}

Leetcode/InvertTree.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
public:
12+
TreeNode* invertTree(TreeNode* root) {
13+
if(!root)
14+
return NULL;
15+
16+
TreeNode* temp = invertTree(root->right);
17+
root->right = invertTree(root->left);
18+
root->left = temp;
19+
return root;
20+
}
21+
};

Leetcode/MoveZeroes.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
void moveZeroes(vector<int>& nums) {
4+
5+
int j = 0;
6+
for(int i=0;i<nums.size();i++){
7+
if(nums[i] != 0)
8+
swap(nums[i],nums[j++]);
9+
}
10+
11+
}
12+
};

Leetcode/ReverseLinkedList.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode(int x) : val(x), next(NULL) {}
7+
* };
8+
*/
9+
class Solution {
10+
public:
11+
12+
ListNode* h;
13+
14+
void helper(ListNode* curr,ListNode* prev){
15+
if(!curr)
16+
h = prev;
17+
else{
18+
helper(curr->next,curr);
19+
curr->next = prev;
20+
}
21+
}
22+
23+
ListNode* reverseList(ListNode* head) {
24+
helper(head,NULL);
25+
return h;
26+
}
27+
};

0 commit comments

Comments
 (0)