Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
liubang committed Nov 30, 2023
1 parent 8ac6160 commit fee9912
Show file tree
Hide file tree
Showing 200 changed files with 6,580 additions and 6,258 deletions.
241 changes: 238 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,239 @@
---
Language: Cpp
BasedOnStyle: Chromium
...
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: false
AcrossComments: true
AlignCompound: false
PadOperators: false
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
- __unused
BinPackArguments: true
BinPackParameters: false
BitFieldColonSpacing: Both
# BreakBeforeBraces: Attach
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAfterAttributes: Never
BreakAfterJavaFieldAnnotations: false
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- CPP
CanonicalDelimiter: ""
BasedOnStyle: llvm
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: ".*"
Priority: 1
IncludeIsMainRegex: "(Test)?$"
# IncludeCategories:
# - Regex: '^"(cpp|playground)/'
# Priority: 2
# SortPriority: 0
# CaseSensitive: false
# - Regex: '^(<|"(gtest|gmock|catch2|isl|json)/)'
# Priority: 3
# SortPriority: 0
# CaseSensitive: false
# - Regex: ".*"
# Priority: 1
# SortPriority: 0
# CaseSensitive: false
# IncludeIsMainRegex: "(Test)?$"
IncludeIsMainSourceRegex: ""
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentGotoLabels: false
IndentExternBlock: AfterExternBlock
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: NextLine
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++20
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseTab: Never
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
---
21 changes: 21 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /bin/bash
#======================================================================
#
# format.sh -
#
# Created by liubang on 2023/09/21 23:27
# Last Modified: 2023/09/21 23:27
#
#======================================================================

CLANG_FORMAT='clang-format -i'

dirs=('include' 'src')

for dir in "${dirs[@]}"; do
find "${dir}" -regex '.*\(\.cc\|\.h|\.cpp\)$' | while read file; do
cmd="${CLANG_FORMAT} ${file}"
echo ${cmd}
eval ${cmd}
done
done
58 changes: 32 additions & 26 deletions include/list.h
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
//=====================================================================
//
// list.h -
//
// Created by liubang on 2023/11/30 23:18
// Last Modified: 2023/11/30 23:18
//
//=====================================================================
#pragma once

#include <functional>
#include <iostream>
#include <vector>

namespace leetcode::list {
struct ListNode {
int val;
ListNode* next;
ListNode(int x, ListNode* next = nullptr) : val(x), next(next) {}
int val;
ListNode* next;
ListNode(int x, ListNode* next = nullptr) : val(x), next(next) {}
};

ListNode* create(const std::vector<int>& vecs) {
if (vecs.empty()) {
return nullptr;
}
auto* root = new ListNode(vecs[0]);
ListNode* cur = root;
for (int i = 1; i < vecs.size(); ++i) {
cur->next = new ListNode(vecs[i]);
cur = cur->next;
}
return root;
if (vecs.empty()) {
return nullptr;
}
auto* root = new ListNode(vecs[0]);
ListNode* cur = root;
for (int i = 1; i < vecs.size(); ++i) {
cur->next = new ListNode(vecs[i]);
cur = cur->next;
}
return root;
}

// 释放无环连表
void destroy(ListNode* node) {
ListNode* cur = node;
while (cur) {
ListNode* next = cur->next;
delete cur;
cur = next;
}
ListNode* cur = node;
while (cur) {
ListNode* next = cur->next;
delete cur;
cur = next;
}
}

bool equals(ListNode* lhs, ListNode* rhs) {
if (lhs && rhs) {
return lhs->val == rhs->val && equals(lhs->next, rhs->next);
}
return lhs == rhs;
if (lhs && rhs) {
return lhs->val == rhs->val && equals(lhs->next, rhs->next);
}
return lhs == rhs;
}

} // namespace leetcode::list
} // namespace leetcode::list
Loading

0 comments on commit fee9912

Please sign in to comment.