Movatterモバイル変換


[0]ホーム

URL:


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

Commite4b33cc

Browse files
authored
Merge branch 'main' into patch-1
2 parents43bc312 +b2736dd commite4b33cc

File tree

787 files changed

+8306
-5894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

787 files changed

+8306
-5894
lines changed

‎.github/pull_request_template.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[//]:#"Pull Request Template"
2+
[//]:#"Replace values inside of square brackets as well as the square brackets themselves"
3+
4+
-**File(s) Modified**:_[1-Two-Sum.py, 2-Add-Two-Numbers.py, etc...]_
5+
-**Language(s) Used**:_[python, javascript, etc...]_
6+
-**Submission URL**:_[https://leetcode.com/submissions/detail/xxxxxxxxx/]_
7+
8+
[//]:#"Getting the Submission URL"
9+
[//]:#"Go to the leetcode [`Submissions tab`](https://user-images.githubusercontent.com/71089234/180188604-b1ecaf90-bf27-4fd6-a559-5567aebf8930.png)"
10+
[//]:#"and [click on the `Accepted` status of your submission.](https://user-images.githubusercontent.com/71089234/180189321-1a48c33f-aa65-4b29-8aaa-685f4f5f8c9e.png)]"
11+
[//]:#"Finally copy the URL from the nav bar, it should look like https://leetcode.com/submissions/detail/xxxxxxxxx/"

‎.github/workflows/format.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name:Format Files
2+
3+
# cpp
4+
# csharp - https://github.com/dotnet/format ?
5+
# java - prettier-plugin-java
6+
# javascript - prettier
7+
# python - black
8+
# ruby - rufo
9+
# swift - https://github.com/apple/swift-format ?
10+
# typescript - prettier
11+
12+
on:
13+
# pull_request_target:
14+
# types: [opened, synchronize]
15+
workflow_dispatch:
16+
17+
jobs:
18+
Format:
19+
runs-on:ubuntu-latest
20+
21+
strategy:
22+
matrix:
23+
node-version:[16.x]
24+
25+
steps:
26+
-uses:actions/checkout@v3
27+
with:
28+
ref:${{ github.head_ref }}
29+
fetch-depth:1
30+
31+
-name:Use Node.js (dependency)
32+
uses:actions/setup-node@v1
33+
with:
34+
node-version:${{ matrix.node-version }}
35+
36+
-name:Install Rufo (dependency)
37+
run:|
38+
sudo apt update
39+
sudo gem install rufo
40+
41+
-name:Install Prettier
42+
run:|
43+
npm install -g prettier
44+
npm install -g prettier-plugin-java
45+
46+
-name:Install Black
47+
uses:BSFishy/pip-action@v1
48+
with:
49+
packages:black
50+
51+
-name:Format
52+
run:|
53+
prettier --config "$GITHUB_WORKSPACE/.prettierrc" --write "$GITHUB_WORKSPACE/javascript/*.js" 2>&1 ||true
54+
prettier --config "$GITHUB_WORKSPACE/.prettierrc" --write "$GITHUB_WORKSPACE/typescript/*.ts" 2>&1 ||true
55+
prettier --config "$GITHUB_WORKSPACE/.prettierrc" --write "$GITHUB_WORKSPACE/java/*.java" 2>&1 ||true
56+
rufo "$GITHUB_WORKSPACE/ruby" 2>&1 ||true
57+
python -m black "$GITHUB_WORKSPACE/" 2>&1 ||true
58+
59+
-name:Push
60+
run:|
61+
git config --global user.email "71089234+Ahmad-A0@users.noreply.github.com"
62+
git config --global user.name "Bot-A0"
63+
git add .
64+
git commit -m "🎨 Format files (🛠️ from Github Actions)" ||true
65+
git push ||true

‎.prettierrc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"endOfLine": "lf",
5+
"tabWidth": 4,
6+
"overrides": [
7+
{
8+
"files": ["javascript/*.js"],
9+
"options": {}
10+
},
11+
{
12+
"files": ["typescript/*.ts"],
13+
"options": {}
14+
},
15+
{
16+
"files": ["ruby/*.rb"],
17+
"options": {}
18+
},
19+
{
20+
"files": ["java/*.java"],
21+
"options": {}
22+
}
23+
]
24+
}

‎.rufo

Whitespace-only changes.

‎1-Two-Sum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classSolution:
22
deftwoSum(self,nums:List[int],target:int)->List[int]:
3-
prevMap= {}# val -> index
4-
3+
prevMap= {}# val -> index
4+
55
fori,ninenumerate(nums):
66
diff=target-n
77
ifdiffinprevMap:

‎10-Regular-Expression-Matching.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,44 @@ class Solution:
33
defisMatch(self,s:str,p:str)->bool:
44
cache= [[False]* (len(p)+1)foriinrange(len(s)+1)]
55
cache[len(s)][len(p)]=True
6-
6+
77
foriinrange(len(s),-1,-1):
8-
forjinrange(len(p)-1,-1 ,-1):
8+
forjinrange(len(p)-1,-1,-1):
99
match=i<len(s)and (s[i]==p[j]orp[j]==".")
10-
10+
1111
if (j+1)<len(p)andp[j+1]=="*":
1212
cache[i][j]=cache[i][j+2]
1313
ifmatch:
1414
cache[i][j]=cache[i+1][j]orcache[i][j]
1515
elifmatch:
16-
cache[i][j]=cache[i+1][j+1]
17-
16+
cache[i][j]=cache[i+1][j+1]
17+
1818
returncache[0][0]
19-
20-
19+
20+
2121
# TOP DOWN MEMOIZATION
2222
classSolution:
2323
defisMatch(self,s:str,p:str)->bool:
2424
cache= {}
25-
25+
2626
defdfs(i,j):
2727
if (i,j)incache:
2828
returncache[(i,j)]
2929
ifi>=len(s)andj>=len(p):
3030
returnTrue
3131
ifj>=len(p):
3232
returnFalse
33-
33+
3434
match=i<len(s)and (s[i]==p[j]orp[j]==".")
3535
if (j+1)<len(p)andp[j+1]=="*":
36-
cache[(i,j)]= (dfs(i,j+2)or# dont use *
37-
(matchanddfs(i+1,j)))# use *
36+
cache[(i,j)]=dfs(i,j+2)or (# dont use *
37+
matchanddfs(i+1,j)
38+
)# use *
3839
returncache[(i,j)]
3940
ifmatch:
40-
cache[(i,j)]=dfs(i+1,j+1)
41-
returncache[(i,j)]
42-
cache[(i,j)]=False
41+
cache[(i,j)]=dfs(i+1,j+1)
42+
returncache[(i,j)]
43+
cache[(i,j)]=False
4344
returnFalse
44-
45+
4546
returndfs(0,0)

‎100-Same-Tree.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
# self.left = None
66
# self.right = None
77

8+
89
classSolution:
910
defisSameTree(self,p:TreeNode,q:TreeNode)->bool:
10-
ifnotpandnotq:returnTrue
11-
ifpandqandp.val==q.val:
11+
ifnotpandnotq:
12+
returnTrue
13+
ifpandqandp.val==q.val:
1214
returnself.isSameTree(p.left,q.left)andself.isSameTree(p.right,q.right)
13-
else:returnFalse
15+
else:
16+
returnFalse

‎102-Binary-Tree-Level-Order-Traversal.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
# self.left = None
66
# self.right = None
77

8+
89
classSolution:
910
deflevelOrder(self,root:TreeNode)->List[List[int]]:
1011
res= []
1112
q=collections.deque()
12-
ifroot:q.append(root)
13-
13+
ifroot:
14+
q.append(root)
15+
1416
whileq:
1517
val= []
16-
18+
1719
foriinrange(len(q)):
1820
node=q.popleft()
1921
val.append(node.val)
20-
ifnode.left:q.append(node.left)
21-
ifnode.right:q.append(node.right)
22+
ifnode.left:
23+
q.append(node.left)
24+
ifnode.right:
25+
q.append(node.right)
2226
res.append(val)
2327
returnres

‎104-Maximum-Depth-of-Binary-Tree.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,36 @@ class Solution:
33
defmaxDepth(self,root:TreeNode)->int:
44
ifnotroot:
55
return0
6-
6+
77
return1+max(self.maxDepth(root.left),self.maxDepth(root.right))
88

9-
# ITERATIVE DFS
9+
10+
# ITERATIVE DFS
1011
classSolution:
1112
defmaxDepth(self,root:TreeNode)->int:
1213
stack= [[root,1]]
1314
res=0
14-
15+
1516
whilestack:
1617
node,depth=stack.pop()
17-
18+
1819
ifnode:
1920
res=max(res,depth)
2021
stack.append([node.left,depth+1])
2122
stack.append([node.right,depth+1])
2223
returnres
2324

25+
2426
# BFS
2527
classSolution:
2628
defmaxDepth(self,root:TreeNode)->int:
2729
ifnotroot:
2830
return0
29-
31+
3032
level=0
3133
q=deque([root])
3234
whileq:
33-
35+
3436
foriinrange(len(q)):
3537
node=q.popleft()
3638
ifnode.left:

‎1046-Last-Stone-Weight.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ class Solution:
22
deflastStoneWeight(self,stones:List[int])->int:
33
stones= [-sforsinstones]
44
heapq.heapify(stones)
5-
5+
66
whilelen(stones)>1:
77
first=heapq.heappop(stones)
88
second=heapq.heappop(stones)
99
ifsecond>first:
1010
heapq.heappush(stones,first-second)
11-
11+
1212
stones.append(0)
1313
returnabs(stones[0])
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
classSolution:
22
defbuildTree(self,preorder:List[int],inorder:List[int])->Optional[TreeNode]:
33
inorder_index_mapping= {}
4-
fork,vinenumerate(inorder):
4+
fork,vinenumerate(inorder):
55
inorder_index_mapping[v]=k
66
index=0
7-
defbuildtree(left,right):
7+
8+
defbuildtree(left,right):
89
nonlocalindex
9-
ifleft>right:
10+
ifleft>right:
1011
returnNone
11-
root_val=preorder[index]
12+
root_val=preorder[index]
1213
root=TreeNode(root_val)
13-
index+=1
14-
root.left=buildtree(left,inorder_index_mapping[root_val]-1)
15-
root.right=buildtree(inorder_index_mapping[root_val]+1,right)
14+
index+=1
15+
root.left=buildtree(left,inorder_index_mapping[root_val]-1)
16+
root.right=buildtree(inorder_index_mapping[root_val]+1,right)
1617
returnroot
17-
returnbuildtree(0,len(preorder)-1)
18+
19+
returnbuildtree(0,len(preorder)-1)

‎11-Container-With-Most-Water.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Solution:
22
defmaxArea(self,height:List[int])->int:
33
l,r=0,len(height)-1
44
res=0
5-
5+
66
whilel<r:
77
res=max(res,min(height[l],height[r])* (r-l))
88
ifheight[l]<height[r]:

‎110-Balanced-Binary-Tree.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
# self.right = right
77
classSolution:
88
defisBalanced(self,root:Optional[TreeNode])->bool:
9-
109
defdfs(root):
11-
ifnotroot:return [True,0]
12-
10+
ifnotroot:
11+
return [True,0]
12+
1313
left,right=dfs(root.left),dfs(root.right)
14-
balanced= (left[0]andright[0]and
15-
abs(left[1]-right[1])<=1)
14+
balanced=left[0]andright[0]andabs(left[1]-right[1])<=1
1615
return [balanced,1+max(left[1],right[1])]
16+
1717
returndfs(root)[0]

‎1143-Longest-Common-Subsequence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
classSolution:
22
deflongestCommonSubsequence(self,text1:str,text2:str)->int:
33
dp= [[0forjinrange(len(text2)+1)]foriinrange(len(text1)+1)]
4-
4+
55
foriinrange(len(text1)-1,-1,-1):
66
forjinrange(len(text2)-1,-1,-1):
77
iftext1[i]==text2[j]:
88
dp[i][j]=1+dp[i+1][j+1]
99
else:
1010
dp[i][j]=max(dp[i][j+1],dp[i+1][j])
11-
11+
1212
returndp[0][0]

‎115-Distinct-Subsequences.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
classSolution:
22
defnumDistinct(self,s:str,t:str)->int:
33
cache= {}
4-
4+
55
foriinrange(len(s)+1):
66
cache[(i,len(t))]=1
77
forjinrange(len(t)):
88
cache[(len(s),j)]=0
9-
9+
1010
foriinrange(len(s)-1,-1,-1):
1111
forjinrange(len(t)-1,-1,-1):
1212
ifs[i]==t[j]:
13-
cache[(i,j)]=cache[(i+1,j+1)]+cache[(i+1,j)]
13+
cache[(i,j)]=cache[(i+1,j+1)]+cache[(i+1,j)]
1414
else:
15-
cache[(i,j)]=cache[(i+1,j)]
16-
returncache[(0,0)]
15+
cache[(i,j)]=cache[(i+1,j)]
16+
returncache[(0,0)]

‎12-Integer-To-Roman.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
classSolution:
22
defintToRoman(self,num:int)->str:
3-
symList= [["I",1], ["IV" ,4], ["V" ,5], ["IX" ,9],
4-
["X" ,10], ["XL" ,40], ["L" ,50], ["XC" ,90],
5-
["C" ,100], ["CD",400], ["D",500], ["CM",900],
6-
["M" ,1000]]
3+
symList= [
4+
["I",1],
5+
["IV",4],
6+
["V",5],
7+
["IX",9],
8+
["X",10],
9+
["XL",40],
10+
["L",50],
11+
["XC",90],
12+
["C",100],
13+
["CD",400],
14+
["D",500],
15+
["CM",900],
16+
["M",1000],
17+
]
718
res=""
819
forsym,valinreversed(symList):
920
ifnum//val:
1021
count=num//val
11-
res+=(sym*count)
22+
res+=sym*count
1223
num=num%val
1324
returnres

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp