mirror of
https://github.com/McSmog/LeetCode-Questions-CompanyWise.git
synced 2026-04-20 00:57:31 +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.5 KiB
1.5 KiB
| 1 | ID | Title | Acceptance | Difficulty | Frequency | Leetcode Question Link |
|---|---|---|---|---|---|---|
| 2 | 915 | Partition Array into Disjoint Intervals | 45.4% | Medium | 0.31069289452415816 | https://leetcode.com/problems/partition-array-into-disjoint-intervals |
| 3 | 984 | String Without AAA or BBB | 37.7% | Medium | 0.2735260204188947 | https://leetcode.com/problems/string-without-aaa-or-bbb |
| 4 | 527 | Word Abbreviation | 54.3% | Hard | 0.18138862486051793 | https://leetcode.com/problems/word-abbreviation |
| 5 | 1017 | Convert to Base -2 | 59.0% | Medium | 0.11681477365175295 | https://leetcode.com/problems/convert-to-base-2 |
| 6 | 983 | Minimum Cost For Tickets | 60.5% | Medium | 0.02467737809337621 | https://leetcode.com/problems/minimum-cost-for-tickets |
| 7 | 42 | Trapping Rain Water | 48.9% | Hard | 0.009762524655659178 | https://leetcode.com/problems/trapping-rain-water |
| 8 | 2 | Add Two Numbers | 33.9% | Medium | 0.006737434951993369 | https://leetcode.com/problems/add-two-numbers |
| 9 | 41 | First Missing Positive | 32.0% | Hard | 0.0064113058208121855 | https://leetcode.com/problems/first-missing-positive |
| 10 | 234 | Palindrome Linked List | 39.3% | Easy | 0.004533613114828982 | https://leetcode.com/problems/palindrome-linked-list |
| 11 | 238 | Product of Array Except Self | 60.1% | Medium | 0.003930436424724545 | https://leetcode.com/problems/product-of-array-except-self |
| 12 | 215 | Kth Largest Element in an Array | 55.4% | Medium | 0.003902443976931749 | https://leetcode.com/problems/kth-largest-element-in-an-array |
| 13 | 121 | Best Time to Buy and Sell Stock | 50.5% | Easy | 0.0021239321954525975 | https://leetcode.com/problems/best-time-to-buy-and-sell-stock |