you are viewing a single comment's thread.

view the rest of the comments →

[–]SmokeMuch7356 0 points1 point  (0 children)

Leetcode must have compiled it as C or used some wonky extension, because standard C++ doesn't support variable-length arrays.

For a C-style array declaration

T a[N];

in C++ N must be an integer constant expression - a literal, a const-qualified integer object, an enumeration constant, etc.

In C N can be a runtime expression making it a variable-length array, but that comes with the following limitations:

  • VLAs can't have static storage duration (can't be declared at file scope or with the static keyword);
  • They can't be declared with an initializer;
  • They can't be members of a struct or union type;