# Why do I get different result compared to my local machine?

• ``````class Solution {
public:
int Min(int x,int y)
{
if(x<y) return x;
return y;
}
int trap(int a[], int n)
{
int count=0,i,start,j;
bool trap;
//while(1)
//{
i=1;
//	trap=false;
while(i<=n-2)
{
while(a[i-1]>a[i] && a[i]<=a[i+1])
{
start=i;
while(i<=n-2 && a[i]==a[i+1])
i++;
if(a[i]<a[i+1])
{
count+=(i-start+1)*(Min(a[start-1],a[i+1])-a[start]);
//trap=true;
for(j=start;j<=i;j++)
a[j]=Min(a[start-1],a[i+1]);

j=start;
while(j>=1 && a[j-1]==a[j])
j--;
if(j>=1)
{
if(a[j-1]>a[j])
i=j;
else
break;
}
else
;
}
else
;
}
//else
//	;
i++;
}
//	if(trap==false)
//		break;
//}
return count;
}
};
``````

I use one pass algorithm, and use Min in case that leetcode do not support C++11, but when in case [4,2,3], my local get 1, which is correct, but leetcode OJ said I print out 3, which is not correct, could anybody help me?

• I have described it clearly........

• There is no comment in code or any detail thought about it.

• I have found my error, I use MSVC to compile, while in this code, gcc get different result, but currently I do not know which part are different between MSVC and GCC compilor, could you help me thanks

• I have solved it, it's my code bug, and MSVC is bad......

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.