Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e632bc9

Browse files
committed
add 3 problems
1 parent fc81942 commit e632bc9

File tree

5 files changed

+474
-0
lines changed

5 files changed

+474
-0
lines changed

‎.clang-format

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: Google
4+
AccessModifierOffset: -1
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveAssignments: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlines: Left
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllArgumentsOnNextLine: true
12+
AllowAllConstructorInitializersOnNextLine: true
13+
AllowAllParametersOfDeclarationOnNextLine: true
14+
AllowShortBlocksOnASingleLine: false
15+
AllowShortCaseLabelsOnASingleLine: false
16+
AllowShortFunctionsOnASingleLine: All
17+
AllowShortLambdasOnASingleLine: All
18+
AllowShortIfStatementsOnASingleLine: WithoutElse
19+
AllowShortLoopsOnASingleLine: true
20+
AlwaysBreakAfterDefinitionReturnType: None
21+
AlwaysBreakAfterReturnType: None
22+
AlwaysBreakBeforeMultilineStrings: true
23+
AlwaysBreakTemplateDeclarations: Yes
24+
BinPackArguments: true
25+
BinPackParameters: true
26+
BraceWrapping:
27+
AfterCaseLabel: false
28+
AfterClass: false
29+
AfterControlStatement: false
30+
AfterEnum: false
31+
AfterFunction: false
32+
AfterNamespace: false
33+
AfterObjCDeclaration: false
34+
AfterStruct: false
35+
AfterUnion: false
36+
AfterExternBlock: false
37+
BeforeCatch: false
38+
BeforeElse: false
39+
IndentBraces: false
40+
SplitEmptyFunction: true
41+
SplitEmptyRecord: true
42+
SplitEmptyNamespace: true
43+
BreakBeforeBinaryOperators: None
44+
BreakBeforeBraces: Attach
45+
BreakBeforeInheritanceComma: false
46+
BreakInheritanceList: BeforeColon
47+
BreakBeforeTernaryOperators: true
48+
BreakConstructorInitializersBeforeComma: false
49+
BreakConstructorInitializers: BeforeColon
50+
BreakAfterJavaFieldAnnotations: false
51+
BreakStringLiterals: true
52+
ColumnLimit: 80
53+
CommentPragmas: '^ IWYU pragma:'
54+
CompactNamespaces: false
55+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
56+
ConstructorInitializerIndentWidth: 4
57+
ContinuationIndentWidth: 4
58+
Cpp11BracedListStyle: true
59+
DerivePointerAlignment: true
60+
DisableFormat: false
61+
ExperimentalAutoDetectBinPacking: false
62+
FixNamespaceComments: true
63+
ForEachMacros:
64+
- foreach
65+
- Q_FOREACH
66+
- BOOST_FOREACH
67+
IncludeBlocks: Regroup
68+
IncludeCategories:
69+
- Regex: '^<ext/.*\.h>'
70+
Priority: 2
71+
- Regex: '^<.*\.h>'
72+
Priority: 1
73+
- Regex: '^<.*'
74+
Priority: 2
75+
- Regex: '.*'
76+
Priority: 3
77+
IncludeIsMainRegex: '([-_](test|unittest))?$'
78+
IndentCaseLabels: true
79+
IndentPPDirectives: None
80+
IndentWidth: 2
81+
IndentWrappedFunctionNames: false
82+
JavaScriptQuotes: Leave
83+
JavaScriptWrapImports: true
84+
KeepEmptyLinesAtTheStartOfBlocks: false
85+
MacroBlockBegin: ''
86+
MacroBlockEnd: ''
87+
MaxEmptyLinesToKeep: 1
88+
NamespaceIndentation: None
89+
ObjCBinPackProtocolList: Never
90+
ObjCBlockIndentWidth: 2
91+
ObjCSpaceAfterProperty: false
92+
ObjCSpaceBeforeProtocolList: true
93+
PenaltyBreakAssignment: 2
94+
PenaltyBreakBeforeFirstCallParameter: 1
95+
PenaltyBreakComment: 300
96+
PenaltyBreakFirstLessLess: 120
97+
PenaltyBreakString: 1000
98+
PenaltyBreakTemplateDeclaration: 10
99+
PenaltyExcessCharacter: 1000000
100+
PenaltyReturnTypeOnItsOwnLine: 200
101+
PointerAlignment: Left
102+
RawStringFormats:
103+
- Language: Cpp
104+
Delimiters:
105+
- cc
106+
- CC
107+
- cpp
108+
- Cpp
109+
- CPP
110+
- 'c++'
111+
- 'C++'
112+
CanonicalDelimiter: ''
113+
BasedOnStyle: google
114+
- Language: TextProto
115+
Delimiters:
116+
- pb
117+
- PB
118+
- proto
119+
- PROTO
120+
EnclosingFunctions:
121+
- EqualsProto
122+
- EquivToProto
123+
- PARSE_PARTIAL_TEXT_PROTO
124+
- PARSE_TEST_PROTO
125+
- PARSE_TEXT_PROTO
126+
- ParseTextOrDie
127+
- ParseTextProtoOrDie
128+
CanonicalDelimiter: ''
129+
BasedOnStyle: google
130+
ReflowComments: true
131+
SortIncludes: true
132+
SortUsingDeclarations: true
133+
SpaceAfterCStyleCast: false
134+
SpaceAfterLogicalNot: false
135+
SpaceAfterTemplateKeyword: true
136+
SpaceBeforeAssignmentOperators: true
137+
SpaceBeforeCpp11BracedList: false
138+
SpaceBeforeCtorInitializerColon: true
139+
SpaceBeforeInheritanceColon: true
140+
SpaceBeforeParens: ControlStatements
141+
SpaceBeforeRangeBasedForLoopColon: true
142+
SpaceInEmptyParentheses: false
143+
SpacesBeforeTrailingComments: 2
144+
SpacesInAngles: false
145+
SpacesInContainerLiterals: true
146+
SpacesInCStyleCastParentheses: false
147+
SpacesInParentheses: false
148+
SpacesInSquareBrackets: false
149+
Standard: Auto
150+
StatementMacros:
151+
- Q_UNUSED
152+
- QT_REQUIRE_VERSION
153+
TabWidth: 8
154+
UseTab: Never
155+
...
156+

‎july/04.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
typedef long long int ll;
6+
typedef pair<int, int> ii;
7+
typedef vector<int> vi;
8+
typedef vector<string> vs;
9+
10+
#define len(container) int((container).size())
11+
#define all(c) (c).begin(), (c).end()
12+
13+
const int M = 1e9 + 7;
14+
15+
template <typename ITER>
16+
void show(ITER begin, ITER end) {
17+
for (int i = 1; begin != end; i++) {
18+
printf("%d ", *(begin++));
19+
if (i % 20 == 0 or begin == end) printf("\n");
20+
}
21+
};
22+
23+
template <typename T>
24+
void addMod(T& a, T b) {
25+
a = (a + b) % M;
26+
}
27+
28+
inline bool isValid(int x, int y, int R, int C) {
29+
return x >= 0 && x < R && y >= 0 && y < C;
30+
}
31+
32+
struct TreeNode {
33+
int val;
34+
TreeNode* left;
35+
TreeNode* right;
36+
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
37+
};
38+
39+
class Solution {
40+
public:
41+
int nthUglyNumber(int n) {
42+
43+
if (n==1) {
44+
return 1;
45+
}
46+
vector<int> nums(n);
47+
int l2 =0, l3 = 0, l5 = 0;
48+
nums[0] = 1;
49+
for (int i = 1; i < n; ++i) {
50+
while(2*nums[l2] <= nums[i-1] )l2++;
51+
while(3*nums[l3] <= nums[i-1] )l3++;
52+
while(5*nums[l5] <= nums[i-1] )l5++;
53+
nums[i] = min({5*nums[l5], 3*nums[l3], 2*nums[l2]});
54+
if(nums[i] == 2*nums[l2]) l2++;
55+
else if(nums[i] == 3*nums[l3]) l3++;
56+
else l5++;
57+
}
58+
return nums[n-1];
59+
60+
}
61+
};
62+
63+
int main(int argc, char* argv[]) {
64+
// Solution s = Solution();
65+
return 0;
66+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* @lc app=leetcode id=109 lang=cpp
3+
*
4+
* [109] Convert Sorted List to Binary Search Tree
5+
*
6+
* https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/description/
7+
*
8+
* algorithms
9+
* Medium (45.13%)
10+
* Likes: 1971
11+
* Dislikes: 87
12+
* Total Accepted: 241.9K
13+
* Total Submissions: 514.2K
14+
* Testcase Example: '[-10,-3,0,5,9]'
15+
*
16+
* Given a singly linked list where elements are sorted in ascending order,
17+
* convert it to a height balanced BST.
18+
*
19+
* For this problem, a height-balanced binary tree is defined as a binary tree
20+
* in which the depth of the two subtrees of every node never differ by more
21+
* than 1.
22+
*
23+
* Example:
24+
*
25+
*
26+
* Given the sorted linked list: [-10,-3,0,5,9],
27+
*
28+
* One possible answer is: [0,-3,9,-10,null,5], which represents the following
29+
* height balanced BST:
30+
*
31+
* ⁠ 0
32+
* ⁠ / \
33+
* ⁠ -3 9
34+
* ⁠ / /
35+
* ⁠-10 5
36+
*
37+
*
38+
*/
39+
40+
// @lc code=start
41+
/**
42+
* Definition for singly-linked list.
43+
* struct ListNode {
44+
* int val;
45+
* ListNode *next;
46+
* ListNode() : val(0), next(nullptr) {}
47+
* ListNode(int x) : val(x), next(nullptr) {}
48+
* ListNode(int x, ListNode *next) : val(x), next(next) {}
49+
* };
50+
*/
51+
/**
52+
* Definition for a binary tree node.
53+
* struct TreeNode {
54+
* int val;
55+
* TreeNode *left;
56+
* TreeNode *right;
57+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
58+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
59+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left),
60+
* right(right) {}
61+
* };
62+
*/
63+
64+
#include <bits/stdc++.h>
65+
66+
using namespace std;
67+
68+
// struct ListNode {
69+
// int val;
70+
// ListNode *next;
71+
// ListNode() : val(0), next(nullptr) {}
72+
// ListNode(int x) : val(x), next(nullptr) {}
73+
// ListNode(int x, ListNode *next) : val(x), next(next) {}
74+
// };
75+
76+
// struct TreeNode {
77+
// int val;
78+
// TreeNode *left;
79+
// TreeNode *right;
80+
// TreeNode() : val(0), left(nullptr), right(nullptr) {}
81+
// TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
82+
// TreeNode(int x, TreeNode *left, TreeNode *right)
83+
// : val(x), left(left), right(right) {}
84+
// };
85+
86+
class Solution {
87+
public:
88+
TreeNode *sortedListToBST(ListNode *head) {
89+
if (head == nullptr) return nullptr;
90+
if (!head->next) return new TreeNode(head->val);
91+
auto tmp = head;
92+
int depth = 0;
93+
while (tmp != nullptr) {
94+
depth++;
95+
tmp = tmp->next;
96+
}
97+
98+
tmp = head;
99+
ListNode *prev;
100+
for (int i = 0; i < depth / 2; i++) {
101+
prev = tmp;
102+
tmp = tmp->next;
103+
}
104+
prev->next = 0;
105+
106+
TreeNode *r = new TreeNode(tmp->val);
107+
r->left = sortedListToBST(head);
108+
r->right = sortedListToBST(tmp->next);
109+
return r;
110+
}
111+
};
112+
// @lc code=end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /