Skip to content

Instantly share code, notes, and snippets.

@riyafa
Last active March 15, 2022 07:32
Show Gist options
  • Save riyafa/c15bef065e4ce84581a1252f3f0e2baa to your computer and use it in GitHub Desktop.
Save riyafa/c15bef065e4ce84581a1252f3f0e2baa to your computer and use it in GitHub Desktop.
Mathematical solution for 441. Arranging Coins: https://youtu.be/H-Tdu8qJ_uk
class ArrangingCoins {
public int arrangeCoins(int n) {
double result = (-1.0 + Math.sqrt(1.0+8.0*n))/2.0;
return (int)Math.floor(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment