Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Arrays/Repeat_and_Missing_Number_Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
vector<int> Solution::repeatedNumber(const vector<int> &A) {
int n =A.size();
long long int sq1=0,sum1=0,sum2=0,sq2=0,x,a;
Comment on lines +36 to +37
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give 1 space before and after each assignment operator.

a = 10;

vector <int> v(2,0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector<int> v(2, 0);

int i;
for(i=0;i<n;i++){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (i=0; i<n; ++i) 
{

sum2=sum2+long(i+1);
sq2=sq2+long(i+1)*long(i+1);
sum1=sum1+long(A[i]);
sq1=sq1+long(A[i])*long(A[i]);
}

x=(sq1-sq2)/(sum1-sum2);
a=(x+(sum1-sum2))/2;
v[0]=a;
v[1]=x-a;
Comment on lines +41 to +50
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Give appropriate spacing, refer existing code files.
  2. Add code logical comments as what your each block is doing.

return v;
}