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)
```
14 lines
1.3 KiB
CSV
14 lines
1.3 KiB
CSV
ID,Title,Acceptance,Difficulty,Frequency,Leetcode Question Link
|
|
669,Trim a Binary Search Tree,63.0%,Easy,0.015052444911090134, https://leetcode.com/problems/trim-a-binary-search-tree
|
|
384,Shuffle an Array,52.8%,Medium,0.011375721700252122, https://leetcode.com/problems/shuffle-an-array
|
|
77,Combinations,54.7%,Medium,0.008578021081192079, https://leetcode.com/problems/combinations
|
|
1,Two Sum,45.6%,Easy,0.004901297870354067, https://leetcode.com/problems/two-sum
|
|
207,Course Schedule,43.1%,Medium,0.004736539346673217, https://leetcode.com/problems/course-schedule
|
|
42,Trapping Rain Water,48.9%,Hard,0.00411947029523883, https://leetcode.com/problems/trapping-rain-water
|
|
13,Roman to Integer,55.7%,Easy,0.0032749333347487667, https://leetcode.com/problems/roman-to-integer
|
|
200,Number of Islands,46.8%,Medium,0.002765297303115152, https://leetcode.com/problems/number-of-islands
|
|
260,Single Number III,64.3%,Medium,0.002022143148991901, https://leetcode.com/problems/single-number-iii
|
|
7,Reverse Integer,25.8%,Easy,0.0017826905514433007, https://leetcode.com/problems/reverse-integer
|
|
2,Add Two Numbers,33.9%,Medium,0.0016196302686159038, https://leetcode.com/problems/add-two-numbers
|
|
3,Longest Substring Without Repeating Characters,30.4%,Medium,0.0014852223137141987, https://leetcode.com/problems/longest-substring-without-repeating-characters
|