Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1.  
  2. public int matchUp(int[] nums1, int[] nums2) {
  3.  
  4.  //if nums1 is smaller than nums2 (length) run upto nums1 and vice versa
  5.  int min=(nums1.length<=nums2.length)? nums1.length:nums2.length;
  6.  int dif,counter=0;
  7.  for(int i=0;i<min;i++)
  8.  {
  9.   dif=Math.abs(nums1[i]-nums2[i]);
  10.   if(dif<=2 && dif >0)
  11.   {
  12.    counter++;
  13.   }
  14.  }
  15.  
  16.  return counter;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement