Skip to content

Commit ad430cd

Browse files
Merge branch 'main' of https://github.com/contextlab/leetcode-solutions into main
2 parents cdffd8e + dbbb608 commit ad430cd

File tree

5 files changed

+53
-106
lines changed

5 files changed

+53
-106
lines changed

.github/workflows/update_readme.yml

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,12 @@ jobs:
2323
python -m pip install --upgrade pip
2424
pip install requests beautifulsoup4
2525
26-
- name: Run update_readme.py
27-
id: update_readme
26+
- name: Fetch and update README with daily LeetCode problem details
2827
run: python update_readme.py
2928

30-
- name: Create GitHub issue on failure
31-
if: failure()
32-
uses: actions/github-script@v6
29+
- name: Commit and push changes
30+
uses: stefanzweifel/git-auto-commit-action@v4
3331
with:
34-
github-token: ${{ secrets.GITHUB_TOKEN }}
35-
script: |
36-
const issueTitle = "Update README with LeetCode Daily Challenge Failed";
37-
const issueBody = `
38-
The GitHub Action to update README with LeetCode Daily Challenge has failed.
39-
Please check the workflow logs for more details.
40-
`;
41-
42-
const existingIssues = await github.rest.issues.listForRepo({
43-
owner: context.repo.owner,
44-
repo: context.repo.repo,
45-
state: 'open',
46-
labels: 'bug',
47-
});
48-
49-
const issueExists = existingIssues.data.find(issue => issue.title === issueTitle);
50-
51-
if (!issueExists) {
52-
await github.rest.issues.create({
53-
owner: context.repo.owner,
54-
repo: context.repo.repo,
55-
title: issueTitle,
56-
body: issueBody,
57-
labels: ['bug'],
58-
});
59-
} else {
60-
console.log(`An issue with the title "${issueTitle}" already exists.`);
61-
}
32+
commit_message: "Update README with LeetCode Daily Challenge"
33+
branch: main
34+
file_pattern: README.md

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ Each day (ideally) we'll attempt the daily [leetcode](https://leetcode.com) prob
66

77
| 📆 Date | ⚙️ Problem | 📝 Link to notes | 🚦 Difficulty |
88
|--------------|-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|------------|
9-
| July 1, 2024 | [350](https://leetcode.com/problems/intersection-of-two-arrays-ii/) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/350) | 🟢 Easy |
10-
| July 2, 2024 | [1509](https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves/) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/1509) | 🟡 Medium |
11-
| July 3, 2024 | [2181](https://leetcode.com/problems/merge-nodes-in-between-zeros/) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/2181) | 🟡 Medium |
12-
| July 4, 2024 | [2058](https://leetcode.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points/) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/2058) | 🟡 Medium |
9+
| July 1, 2024 | [1550](https://leetcode.com/problems/three-consecutive-odds/description/) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/1550) | 🟢 Easy |
10+
| July 2, 2024 | [350](https://leetcode.com/problems/intersection-of-two-arrays-ii/) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/350) | 🟢 Easy |
11+
| July 3, 2024 | [1509](https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves/) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/1509) | 🟡 Medium |
12+
| July 4, 2024 | [2181](https://leetcode.com/problems/merge-nodes-in-between-zeros/) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/2181) | 🟡 Medium |
13+
| July 5, 2024 | [2058](https://leetcode.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points/) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/2058) | 🟡 Medium |
14+
| July 6, 2024 | [2582](https://leetcode.com/problems/pass-the-pillow) | [Click here](https://github.com/ContextLab/leetcode-solutions/tree/main/problems/2582) | 🟢 Easy |
15+
1316

1417
# Join our discussion!
1518

@@ -19,11 +22,16 @@ If you're a member of [our lab](https://www.context-lab.com/) and/or a [Dartmout
1922

2023
1. Start by [forking](https://github.com/ContextLab/leetcode-solutions/fork) this repository.
2124
2. In your fork, navigate to the [problems](https://github.com/ContextLab/leetcode-solutions/new/main/problems) folder and click the **Add file** button on the right. Choose the **Create new file** option:
22-
- File name: `leetcode-solutions/problems/<PROBLEM NUMBER>/<your name>.md` (where you should replace `<PROBLEM NUMBER>` with the leetcode problem ID code, and `<your name>` with your first name, in lowercase letters. E.g., [Jeremy](https://www.context-lab.com/people)'s solution to problem 350 would be named `leetcode-solutions/blob/main/problems/350/jeremy.md`
25+
- File name: `leetcode-solutions/problems/<PROBLEM NUMBER>/<your name>.md` (where you should replace `<PROBLEM NUMBER>` with the leetcode problem ID code, and `<your name>` with either your first name or your GitHub username (your choice!), in lowercase letters. E.g., [Jeremy](https://www.context-lab.com/people)'s solution to problem 350 would be named `leetcode-solutions/blob/main/problems/350/jeremy.md`
2326
- Contents: Any format is fine, but we suggest starting with our [template file](https://github.com/ContextLab/leetcode-solutions/blob/main/problems/template.md). Then add your notes/solution as you solve the problem! Make sure to commit your changes (and it's fine to make multiple commits as you're working on the problem).
2427
3. Once you've added your file, start a [pull request](https://github.com/ContextLab/leetcode-solutions/pulls) to add it into the ContextLab fork so that others can see how you approached the problem.
2528
4. Also make sure that the problem has been added to the [table](https://github.com/ContextLab/leetcode-solutions#problems-weve-attempted-thus-far). If you're the first one to work on a problem, you'll need to add a row for it. Problems should be listed in chronological order from top (earliest) to bottom (latest).
2629

30+
# Other stuff
31+
32+
- Click [here](https://github.com/ContextLab/leetcode-solutions/actions/workflows/create_new_note.yml) and then click "Run workflow" to run our shortcut action for creating a new note for the daily problem based on the template.md file. Then click the link to the notes on today's problem in the last row [table above](https://github.com/ContextLab/leetcode-solutions#problems-weve-attempted-thus-far) and you should see a markdown (.md) file named for your GitHub username. Edit that to add your notes!
33+
- The [table](https://github.com/ContextLab/leetcode-solutions#problems-weve-attempted-thus-far) listing each day's problems and links to our solutions *should* be updated automatically via [this action](https://github.com/ContextLab/leetcode-solutions/actions/workflows/update_readme.yml) (run each day at 00:01 UTC, which is 1 minute after the daily problems are released).
34+
2735
# Question? Comments? Concerns?
2836

2937
You can work through problems "live" in our [Slack channel](https://app.slack.com/client/EQ19QMD6Z/C0753BB4MC5). To make comments on a specific solution, make suggestions for this repository in general, etc., consider filing an [issue](https://github.com/ContextLab/leetcode-solutions/issues).

create_note.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

problems/1550/jeremy.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# [Problem 1550: Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds/description/)
2+
3+
## Initial thoughts (stream-of-consciousness)
4+
- This seems easy. I'll keep a running count of consecutive odds. If an even number is encountered, reset the counter. If the counter hits 3, return True. At the end of the list (if the counter has not yet hit 3), return False.
5+
6+
## Attempted solution(s)
7+
```python
8+
class Solution:
9+
def threeConsecutiveOdds(self, arr: List[int]) -> bool:
10+
counter = 0
11+
for x in arr:
12+
if x %2 == 0:
13+
counter = 0
14+
else:
15+
counter += 1
16+
if counter == 3:
17+
return True
18+
return False
19+
```
20+
- The given test cases pass; the problem is also too simply to have tricky cases
21+
- Submitting...
22+
23+
<img width="657" alt="Screenshot 2024-07-05 at 7 50 37 PM" src="https://github.com/ContextLab/leetcode-solutions/assets/9030494/dfd800db-f1c0-4cc1-8f8e-a02f75521656">
24+
25+
Problem solved!

update_readme.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import requests
22
import json
33
from datetime import datetime
4-
from bs4 import BeautifulSoup
54

65
# Set variables
76
date_str = datetime.now().strftime('%B %-d, %Y')
@@ -31,53 +30,23 @@
3130
# Debug: Print the entire response to check its structure
3231
print(json.dumps(data, indent=2))
3332

34-
# Fetch the daily challenge details from the daily challenge page for verification
35-
daily_challenge_page = requests.get("https://leetcode.com/problemset/all/")
36-
soup = BeautifulSoup(daily_challenge_page.content, 'html.parser')
37-
38-
# Initialize variables for cross-verified details
39-
daily_challenge_title = None
40-
daily_challenge_slug = None
41-
daily_challenge_id = None
42-
43-
# Attempt to fetch the daily challenge details
44-
try:
45-
daily_challenge_section = soup.find('div', {'class': 'question-list-table'})
46-
if daily_challenge_section:
47-
first_problem = daily_challenge_section.find_all('tr')[1] # Skip header row
48-
daily_challenge_title = first_problem.find('a', {'class': 'title'}).text.strip()
49-
daily_challenge_slug = first_problem.find('a', {'class': 'title'})['href'].strip().split('/')[-2]
50-
daily_challenge_id = first_problem.find_all('td')[1].text.strip()
51-
52-
# Print the cross-verified details for debugging
53-
print(f"Cross-verified Title: {daily_challenge_title}")
54-
print(f"Cross-verified Slug: {daily_challenge_slug}")
55-
print(f"Cross-verified ID: {daily_challenge_id}")
56-
else:
57-
raise Exception("Error: Could not fetch the daily challenge from the problem set page.")
58-
except Exception as e:
59-
print(f"Error: Exception occurred while fetching daily challenge details: {e}")
60-
raise
61-
6233
# Check if the expected data is present in the API response
6334
if 'data' in data and 'activeDailyCodingChallengeQuestion' in data['data']:
6435
problem = data['data']['activeDailyCodingChallengeQuestion']['question']
65-
problem_id = problem['questionId']
36+
problem_id = problem['questionFrontendId']
6637
title = problem['title']
6738
title_slug = problem['titleSlug']
6839
link = f"https://leetcode.com/problems/{title_slug}"
6940
difficulty = problem['difficulty']
7041
difficulty_icon = "🟢" if difficulty == "Easy" else "🟡" if difficulty == "Medium" else "🔴"
7142
note_link = f"{repo_url}/tree/main/problems/{problem_id}"
7243

73-
# Print the API details for debugging
74-
print(f"API Title: {title}")
75-
print(f"API Slug: {title_slug}")
76-
print(f"API ID: {problem_id}")
77-
78-
# Check if the API title and slug match the cross-verified title and slug
79-
if daily_challenge_title and (daily_challenge_title != title or daily_challenge_slug != title_slug):
80-
raise Exception("Error: The titles or slugs do not match. The API might be providing incorrect details.")
44+
# Print the fetched problem details for debugging
45+
print(f"Problem ID: {problem_id}")
46+
print(f"Title: {title}")
47+
print(f"Title Slug: {title_slug}")
48+
print(f"Link: {link}")
49+
print(f"Difficulty: {difficulty}")
8150

8251
# Create the new entry
8352
new_entry = f"| {date_str} | [{problem_id}]({link}) | [Click here]({note_link}) | {difficulty_icon} {difficulty} |"
@@ -113,12 +82,12 @@
11382
table_content[-1] = table_content[-1].rstrip()
11483

11584
# Rebuild the README with the new entry added to the table
116-
updated_readme = before_table + table_content + [new_entry + '\n'] + after_table
85+
updated_readme = before_table + table_content + [new_entry + '\n\n'] + after_table
11786

11887
# Overwrite the README file with the updated content
11988
with open(readme_file, 'w') as file:
12089
file.writelines(updated_readme)
12190

12291
print("README file updated successfully!")
12392
else:
124-
raise Exception("Error: Unexpected response structure.")
93+
print("Error: Unexpected response structure.")

0 commit comments

Comments
 (0)