This repository contains C++, Java, and Python solutions to LeetCode.
Also, I build a website by GitHub Actions to host the code files by Markdown files. You can see the built page here: LeetCode Solutions.
I believe messy code is costing you.
Therefore, I follow the formatter 99% of the time, but in rare situations, I format the code manually because it might look better in these cases.
Saving vertical rows and trying to squeeze everything in a single line disrespects the column limit and makes the code hard to read.
This repository aims to provide code with good readability and consistent style over various topics and embraces new standards. In most situations, readability has more value than lines of code and tiny performance hop.
- C++ code is formatted by clang-format following the Google C++ Style Guide. You can see the configuration here.
- Java code is formatted by clang-format following the Google Java Style Guide.
- Python code is formatted by autopep8 following PEP 8 -- Style Guide for Python Code except passing the argument
--indent-size=2
for a better viewing experience in mobile devices.
Take a look at my nvim configuration related to auto formatting.
In ~/.config/nvim/init.lua
:
local LUA_DIR = '$HOME/.config/nvim/lua/'
local function sourceLuaFiles(subpath)
local p = io.popen('ls ' .. LUA_DIR .. subpath .. '| grep .lua')
for filename in p:lines() do
local fsPath = subpath .. filename
local requirePath = fsPath:gsub('%.lua', ''):gsub('/', '.')
require(requirePath)
end
end
sourceLuaFiles('')
sourceLuaFiles('plugins/')
In ~/.config/nvim/lua/plugins.lua
:
-- Use packer plugin
local status_ok, packer = pcall(require, 'packer')
if not status_ok then return end
-- Install your plugins here
return packer.startup(function(use)
-- Null LS
use 'jose-elias-alvarez/null-ls.nvim' -- for formatters and linters
end)
In ~/.config/nvim/lua/plugins/null-ls.lua
:
local status_ok, null_ls = pcall(require, "null-ls")
if not status_ok then
return
end
local formatting = null_ls.builtins.formatting
null_ls.setup {
debug = false,
sources = {
formatting.autopep8.with { extra_args = { '--indent-size=2' } },
formatting.clang_format,
},
on_attach = function(client)
if client.resolved_capabilities.document_formatting then
-- Format on save
vim.cmd([[
augroup LspFormatting
autocmd! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
augroup END
]])
end
end,
}
The repository is still under construction, and the goal is to keep up with the growth of LeetCode problems by the end of the year!
For more information, please visit my GitHub.
Hosted the site on Feb 23, 2019.
Revised on Dec 25, 2019.
Added init.vim
on Jan 18, 2021.
Updated to init.lua
on Jan 1, 2022.