Guest User

Untitled

a guest
Jan 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. public class Solution {
  2. public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t) {
  3. if(k==0) return false;
  4. if(k>nums.Length) return true;
  5. for(int i=0;i<nums.Length;i++)
  6. {
  7. int varK = 1;
  8. while(varK <= k)
  9. {
  10. if(i+varK < nums.Length)
  11. {
  12.  
  13. if((nums[i]-nums[i+varK]) > 0)
  14. {
  15. if((nums[i]-nums[i+varK]) <= t)
  16. return true;
  17. }
  18. else if((nums[i+varK]-nums[i]) <= t)
  19. return true;
  20.  
  21. }
  22. varK++;
  23. }
  24. }
  25. return false;
  26. }
  27. }
Add Comment
Please, Sign In to add comment