LeetCode Notes

Arrays

  1. Read the constraints before choosing an approach. Consider empty input and boundary cases early.
  2. If compilation reports control reaches end of non-void function, make sure every reachable control path returns a value. A return inside one branch might leave another path uncovered.
  3. When comparing values, check whether equality satisfies the condition.
  4. In C++, prefer ++i when the old value is unnecessary. Post-increment may have to preserve the previous value, particularly for user-defined types.
  5. Use the correct type for Java floating-point literals.
float f = 1.1;     // Invalid: 1.1 is a double literal in Java.
float f = 1.1f;    // Valid.
double d = 34.4;   // Valid.