Skip to content

Commit 86f8b34

Browse files
committed
feat(leetcode): solve 11 - Container With Most Water
1 parent c7ad33f commit 86f8b34

6 files changed

Lines changed: 277 additions & 139 deletions

File tree

leetcode/constants.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
STATUS_MAP = {
2+
10: "Accepted",
3+
11: "Wrong Answer",
4+
12: "Memory Limit Exceeded",
5+
13: "Output Limit Exceeded",
6+
14: "Time Limit Exceeded",
7+
15: "Runtime Error",
8+
16: "Internal Error",
9+
20: "Compile Error",
10+
}

main.py

Lines changed: 6 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,21 @@
1-
from rich.console import Console
2-
from rich.panel import Panel
3-
from rich.table import Table
4-
5-
from sync.detector import SubmissionDetector
6-
7-
from leetcode.auth import LeetCodeAuth
8-
from leetcode.client import LeetCodeClient
9-
from leetcode.api import LeetCodeAPI
10-
111
from config.settings import Config
122

13-
from leetcode.downloader import SubmissionDownloader
14-
15-
from github_sync.manager import GitManager
16-
17-
console = Console()
18-
19-
20-
def banner():
21-
console.print(
22-
Panel.fit(
23-
"[bold cyan]LeetCode Sync[/bold cyan]\n"
24-
"Automatic LeetCode → GitHub Synchronization",
25-
title="v0.4.0",
26-
)
27-
)
28-
29-
30-
def display_statistics(stats):
31-
"""Display solved problem statistics."""
32-
33-
table = Table(title="LeetCode Statistics")
3+
from sync.manager import SyncManager
344

35-
table.add_column("Difficulty", style="cyan")
36-
table.add_column("Solved", justify="right", style="green")
37-
38-
for item in stats:
39-
table.add_row(
40-
item["difficulty"],
41-
str(item["count"])
42-
)
43-
44-
console.print(table)
45-
46-
47-
def display_recent_submissions(submissions):
48-
"""Display recent accepted submissions."""
49-
50-
table = Table(title="Recent Accepted Submissions")
51-
52-
table.add_column("ID", style="cyan")
53-
table.add_column("Title")
54-
table.add_column("Date")
55-
56-
for submission in submissions:
57-
table.add_row(
58-
submission.id,
59-
submission.title,
60-
submission.date.strftime("%Y-%m-%d %H:%M"),
61-
)
62-
63-
console.print(table)
5+
from utils.formatter import display_banner
646

657

668
def main():
9+
6710
Config.validate()
6811
Config.initialize()
6912

70-
banner()
71-
72-
session = LeetCodeAuth().get_session()
73-
api = LeetCodeAPI(
74-
LeetCodeClient(session)
75-
)
76-
77-
# Profile
78-
profile = api.get_profile()
79-
80-
console.print(
81-
f"[bold green]Logged in as:[/bold green] {profile['username']}\n"
82-
)
83-
84-
display_statistics(
85-
profile["submitStatsGlobal"]["acSubmissionNum"]
86-
)
87-
88-
console.print()
89-
90-
# Recent submissions
91-
submissions = api.get_recent_submissions()
92-
93-
94-
detector = SubmissionDetector()
95-
96-
new_submissions = detector.find_new(submissions)
97-
98-
if new_submissions:
99-
console.print(
100-
f"\n[bold green]Found {len(new_submissions)} new submission(s).[/bold green]\n"
101-
)
102-
else:
103-
console.print(
104-
"\n[bold blue]No new submissions found.[/bold blue]\n"
105-
)
106-
107-
for submission in new_submissions:
108-
console.print(f"• {submission.title}")
109-
110-
display_recent_submissions(submissions)
111-
112-
if new_submissions:
113-
detector.update(new_submissions[0])
114-
115-
detail = api.get_submission_detail(
116-
submissions[0].id
117-
)
118-
119-
console.print("\n[bold cyan]Latest Submission Details[/bold cyan]\n")
120-
121-
console.print(f"Question ID : {detail.question_id}")
122-
console.print(f"Slug : {detail.title_slug}")
123-
console.print(f"Language : {detail.language}")
124-
console.print(f"Runtime : {detail.runtime_display}")
125-
console.print(f"Memory : {detail.memory_display}")
126-
127-
128-
STATUS_MAP = {
129-
10: "Accepted",
130-
11: "Wrong Answer",
131-
12: "Memory Limit Exceeded",
132-
13: "Output Limit Exceeded",
133-
14: "Time Limit Exceeded",
134-
15: "Runtime Error",
135-
16: "Internal Error",
136-
20: "Compile Error",
137-
}
138-
console.print(f"Status : {STATUS_MAP.get(detail.status_code, 'Unknown')}")
139-
140-
downloader = SubmissionDownloader()
13+
display_banner()
14114

142-
folder = downloader.download(detail)
143-
144-
console.print(
145-
f"\n[bold green]Solution saved:[/bold green]\n{folder}"
146-
)
15+
manager = SyncManager()
14716

148-
git = GitManager(Config.BASE_DIR)
17+
manager.run()
14918

150-
console.print(git.status())
15119

152-
15320
if __name__ == "__main__":
15421
main()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"submission_id": "2052380776",
3+
"question_id": "11",
4+
"title_slug": "container-with-most-water",
5+
"language": "python3",
6+
"language_verbose": "Python3",
7+
"runtime": "64 ms",
8+
"memory": "29.5 MB",
9+
"status_code": 10,
10+
"timestamp": 1782911682
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def maxArea(self, height: List[int]) -> int:
3+
left=0
4+
right=len(height)-1
5+
max_water=0
6+
7+
while left<right:
8+
area=(right-left)*min(height[left],height[right])
9+
max_water=max(max_water,area)
10+
11+
if height[left]<height[right]:
12+
left+=1
13+
else:
14+
right-=1
15+
return max_water

sync/manager.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from config.settings import Config
2+
3+
from leetcode.auth import LeetCodeAuth
4+
from leetcode.client import LeetCodeClient
5+
from leetcode.api import LeetCodeAPI
6+
from leetcode.downloader import SubmissionDownloader
7+
8+
from sync.detector import SubmissionDetector
9+
10+
from github_sync.manager import GitManager
11+
from github_sync.messages import generate_commit_message
12+
13+
14+
class SyncManager:
15+
"""
16+
Coordinates the complete LeetCode synchronization workflow.
17+
"""
18+
19+
def __init__(self):
20+
session = LeetCodeAuth().get_session()
21+
22+
self.api = LeetCodeAPI(
23+
LeetCodeClient(session)
24+
)
25+
26+
self.detector = SubmissionDetector()
27+
28+
self.downloader = SubmissionDownloader()
29+
30+
self.git = GitManager(Config.BASE_DIR)
31+
32+
def run(self):
33+
"""
34+
Run one synchronization cycle.
35+
"""
36+
37+
submissions = self.api.get_recent_submissions()
38+
39+
new_submissions = self.detector.find_new(submissions)
40+
41+
if not new_submissions:
42+
print("No new submissions found.")
43+
return
44+
45+
latest = new_submissions[0]
46+
47+
detail = self.api.get_submission_detail(latest.id)
48+
49+
self.downloader.download(detail)
50+
51+
self.git.add()
52+
53+
self.git.commit(
54+
generate_commit_message(detail)
55+
)
56+
57+
self.git.push()
58+
59+
self.detector.update(latest)
60+
61+
print(f"Successfully synced: {latest.title}")

0 commit comments

Comments
 (0)