leetcode icon indicating copy to clipboard operation
leetcode copied to clipboard

Use of lowercase "L" as a variable

Open bcatalfo opened this issue 4 years ago • 2 comments

According to PEP 8

Never use the characters ‘l’ (lowercase letter el), ‘O’ (uppercase letter oh), or ‘I’ (uppercase letter eye) as single character variable names. In some fonts, these characters are indistinguishable from the numerals one and zero. When tempted to use ‘l’, use ‘L’ instead.

However several of these solutions use lowercase 'l' usually as a "left" pointer in conjunction with a "right" pointer indicated by 'r'. Personally I would recommend changing these to "L" and "R" but really anything is okay as long as it isn't "l" as it is very confusing. Examples of problems that use this are 424-Longest-Repeating-Character-Replacement and 647-Palindromic-Substrings.

bcatalfo avatar Jul 22 '22 15:07 bcatalfo

PEP8 also says variables should be lowercase, so definitely not R. For optimal readability these kinds of variables should be named left and right in full. That being said, l, r = 0, 1 should be plenty self-descriptive for Leetcode solutions.

flonle avatar Jul 27 '22 10:07 flonle

Stale issue message

github-actions[bot] avatar Oct 25 '22 18:10 github-actions[bot]