Skip to content

Instantly share code, notes, and snippets.

@chaudharisuresh997
Created December 2, 2019 05:01
Show Gist options
  • Save chaudharisuresh997/b97af2086f52fc715c0452ee6a98597b to your computer and use it in GitHub Desktop.
Save chaudharisuresh997/b97af2086f52fc715c0452ee6a98597b to your computer and use it in GitHub Desktop.
Divide int
public class Solution {
public int divide(int A, int B) {
if(A==Integer.MIN_VALUE && B<0){
return Integer.MAX_VALUE;
}else if(A==Integer.MIN_VALUE && B>0){
return Integer.MIN_VALUE;
}
if(A==Integer.MAX_VALUE){
return Integer.MAX_VALUE;
}
int sign=-1;
if(A<0||B<0){
sign=-1;
}else{
sign=1;
}
int q=0;
A=Math.abs(A);
B=Math.abs(B);
while(A>=B){
A-=B;
q++;
}
return sign*q;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment