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 | 529 | Minesweeper | 59.1% | Medium | 0.03486918507635715 | https://leetcode.com/problems/minesweeper |
| 3 | 146 | LRU Cache | 33.2% | Medium | 0.031510805207477295 | https://leetcode.com/problems/lru-cache |
| 4 | 304 | Range Sum Query 2D - Immutable | 38.6% | Medium | 0.023009339909829205 | https://leetcode.com/problems/range-sum-query-2d-immutable |
| 5 | 695 | Max Area of Island | 62.7% | Medium | 0.019939965763769146 | https://leetcode.com/problems/max-area-of-island |
| 6 | 986 | Interval List Intersections | 67.3% | Medium | 0.011438500466121056 | https://leetcode.com/problems/interval-list-intersections |
| 7 | 200 | Number of Islands | 46.8% | Medium | 0.011015601921505717 | https://leetcode.com/problems/number-of-islands |
| 8 | 63 | Unique Paths II | 34.6% | Medium | 0.008375258336732413 | https://leetcode.com/problems/unique-paths-ii |
| 9 | 36 | Valid Sudoku | 48.7% | Medium | 0.0069420618952821065 | https://leetcode.com/problems/valid-sudoku |
| 10 | 23 | Merge k Sorted Lists | 40.2% | Hard | 0.0038759738446929853 | https://leetcode.com/problems/merge-k-sorted-lists |
| 11 | 79 | Word Search | 35.6% | Medium | 0.0016410260092945288 | https://leetcode.com/problems/word-search |