Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. int length = a.length;
  2. int diffCount = 1; //The number of different integers
  3.  
  4. for(int i = 1; i < length; i++)
  5. {
  6. int b = a[i];
  7. int c = a[i-1];
  8.  
  9. if(c>b)
  10. throw new IllegalStateException("unsorted array");
  11.  
  12. if(c!=b)
  13. diffCount++;
  14. }
  15. return diffCount;
  16.  
  17. diffCount += c != b;
  18.  
  19. int b = a[i];
  20. int c = a[i-1];
  21.  
  22. if (c != b) …
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement