mirror of
https://github.com/McSmog/LeetCode-Questions-CompanyWise.git
synced 2026-04-19 16:56:45 +00:00
## Description
- Add headers to all the CSV files
## Script used
```py
import csv
import os
# Set the path of the folder containing the CSV files
folder_path = "./LeetCode-Questions-CompanyWise"
headers = [
"ID",
"Title",
"Acceptance",
"Difficulty",
"Frequency",
"Leetcode Question Link",
]
# Loop through all the CSV files in the folder
for file_name in os.listdir(folder_path):
if file_name.endswith(".csv"):
# Read the CSV file into a list of rows
file_path = os.path.join(folder_path, file_name)
with open(file_path, "r") as f:
reader = csv.reader(f)
rows = list(reader)
has_headers = False
if len(rows) > 0 and rows[0] == headers:
has_headers = True
if not has_headers:
rows.insert(0, headers)
# Write the list of rows back to the CSV file
with open(file_path, "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(rows)
```
1.1 KiB
1.1 KiB
| 1 | ID | Title | Acceptance | Difficulty | Frequency | Leetcode Question Link |
|---|---|---|---|---|---|---|
| 2 | 939 | Minimum Area Rectangle | 51.8% | Medium | 0.03323242792566654 | https://leetcode.com/problems/minimum-area-rectangle |
| 3 | 231 | Power of Two | 43.7% | Easy | 0.021776810232970734 | https://leetcode.com/problems/power-of-two |
| 4 | 146 | LRU Cache | 33.2% | Medium | 0.010321192540274932 | https://leetcode.com/problems/lru-cache |
| 5 | 206 | Reverse Linked List | 62.5% | Easy | 0.009326794511974934 | https://leetcode.com/problems/reverse-linked-list |
| 6 | 114 | Flatten Binary Tree to Linked List | 49.3% | Medium | 0.006896579059060353 | https://leetcode.com/problems/flatten-binary-tree-to-linked-list |
| 7 | 199 | Binary Tree Right Side View | 54.1% | Medium | 0.0056826406650506926 | https://leetcode.com/problems/binary-tree-right-side-view |
| 8 | 22 | Generate Parentheses | 62.7% | Medium | 0.0043611059090124735 | https://leetcode.com/problems/generate-parentheses |
| 9 | 23 | Merge k Sorted Lists | 40.2% | Hard | 0.004051459000748015 | https://leetcode.com/problems/merge-k-sorted-lists |
| 10 | 1 | Two Sum | 45.6% | Easy | 0.003278422738041615 | https://leetcode.com/problems/two-sum |
| 11 | 33 | Search in Rotated Sorted Array | 34.5% | Medium | 0.003229976968332634 | https://leetcode.com/problems/search-in-rotated-sorted-array |