# Notes
Array.Sort(seats); Array.Fill(counts, 1);
When converting math formula to from int
to long
,
Convert the first value to long first,
So the following computation will be long
instead of int
.
Otherwise, the computation will be int
.
Right Way:
long ans = (long)q * l % MOD;
Wrong Way:
long ans = (long)(q * l % MOD);
private int gcd(int x, int y)
{
if (x == 0) return y;
return gcd(y % x, x);
}
int l = a / gcd(a, b) * b;
long distance2 = x * x + y * y;
if (distance2 <= bombI[2] * bombI[2])
{
graph[i][j] = 1;
}
public class Solution
{
public int RangeBitwiseAnd(int left, int right)
{
int result = left;
for (int i = left + 1; i <= right && i > 0; i++)
{
result = result & i;
if (result == 0)
{
return 0;
}
}
return result;
}
}
Without i > 0
, if right is int.MaxValue
, then the next value will be int.MinValue
. Thus the result will be wrong.
private int Min(params int[] values)
{
int result = values[0];
for (int i = 1; i < values.Length; i++)
{
result = Math.Min(result, values[i]);
}
return result;
}
Using StringBuilder
to concatenate strings.
228 Trie 137 Binary Search Tree Iterator 297 Serialize and Deserialize Binary Tree Better finish this first.