Anyone know how to check whether the minus of two integer exceed integer.max_value?

  • 0

    public class Solution {
    public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
    if(nums.length<2) return false;
    int m=0;
    for(int i=0;i<nums.length-1;i++){
    if(i+k>=nums.length) m=nums.length-1;
    else m=i+k;
    for(int j=m;j>i;j--){
    if((long)(nums[j]-nums[i])>2147483647||(long)(nums[j]-nums[i])<=-2147483647) return false;//it is wrong here but i have no idea how to correct it
    if(nums[j]-nums[i]<=t&&nums[i]-nums[j]<=t) return true;
    return false;

Log in to reply

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