Skip to content

Instantly share code, notes, and snippets.

@blzjns
Created June 17, 2025 17:04
Show Gist options
  • Save blzjns/eaee40972919ff27fd885b27a3af654c to your computer and use it in GitHub Desktop.
Save blzjns/eaee40972919ff27fd885b27a3af654c to your computer and use it in GitHub Desktop.
Check whether 3 nums are evenly spaced. E.g. Get the smallest, and largest numbers and use them to calculate the medium, then return whether the diff from mid to small equals the diff from large to mid.
public boolean evenlySpaced(int a, int b, int c) {
int sm = Math.min(Math.min(a, b), c);
int lg = Math.max(Math.max(a, b), c);
//int md = (a+b+c) - (Math.min(Math.min(a,b),c) + Math.max(Math.max(a,b),c));
int md = (a+b+c)-(sm+lg);
return md-sm == lg-md;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment