File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int findDuplicate (vector<int >& nums) {
4
+ map<int ,int > x;
5
+ int ans;
6
+ for (int i=0 ;i<nums.size ();i++)
7
+ {
8
+ x[nums[i]]++;
9
+ if (x[nums[i]]>1 )
10
+ {
11
+ ans=nums[i];
12
+ }
13
+ }
14
+ return ans;
15
+ }
16
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ vector<int > findDuplicates (vector<int >& nums) {
4
+ sort (nums.begin (),nums.end ());
5
+ vector<int > ans;
6
+ for (int i=1 ;i<nums.size ();i++)
7
+ {
8
+ if (nums[i]==nums[i-1 ])
9
+ {
10
+ ans.push_back (nums[i]);
11
+ }
12
+ }
13
+ return ans;
14
+ }
15
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ vector<int > v;
4
+ void tree1 (TreeNode *root)
5
+ {
6
+ if (root!=NULL )
7
+ {
8
+ v.push_back (root->val );
9
+ tree1 (root->left );
10
+ tree1 (root->right );
11
+
12
+ }
13
+ }
14
+ void tree2 (TreeNode *root)
15
+ {
16
+ if (root!=NULL )
17
+ {
18
+ v.push_back (root->val );
19
+ tree2 (root->left );
20
+ tree2 (root->right );
21
+
22
+ }
23
+ }
24
+
25
+ vector<int > getAllElements (TreeNode* root1, TreeNode* root2) {
26
+
27
+ tree1 (root1);
28
+ tree2 (root2);
29
+ sort (v.begin (),v.end ());
30
+ return v;
31
+
32
+ }
33
+ };
You can’t perform that action at this time.
0 commit comments