Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created July 17, 2016 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/f24bc4f8561f29ef5a98d8bd3460d8dd to your computer and use it in GitHub Desktop.
Save jianminchen/f24bc4f8561f29ef5a98d8bd3460d8dd to your computer and use it in GitHub Desktop.
DiffK - facebook code lab - pass all test cases - keep changing the code - line 24 - line 27
public class Solution {
public int diffPossible(List<Integer> a, int b) {
if(a == null || a.size() == 0 || a.size() ==1)
return 0;
int len = a.size();
List<Integer> arrB = new ArrayList<Integer>();
for(int i=0; i< len;i++)
{
int val = a.get(i).intValue();
arrB.add(i, Integer.valueOf( val + b));
}
int start1 = 0;
int start2 = 0;
while(start1 < len && start2 < len )
{
int top = a.get(start1).intValue();
int down = arrB.get(start2).intValue();
if(top == down )
{
if(start1 == start2) // bug001: [1, 2,3], 0, return 0, not 1
{
start1++; // bug002: [1, 2,2,3 ], 0, return 1, not retun 0.
}
else
return 1;
}
else if(top < down)
start1++;
else if(top > down)
start2++;
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment