mirror of
https://github.com/McSmog/LeetCode-Questions-CompanyWise.git
synced 2026-04-19 08:46: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)
```
17 lines
1.6 KiB
CSV
17 lines
1.6 KiB
CSV
ID,Title,Acceptance,Difficulty,Frequency,Leetcode Question Link
|
|
1258,Synonymous Sentences,64.4%,Medium,0.6677654778785802, https://leetcode.com/problems/synonymous-sentences
|
|
146,LRU Cache,33.2%,Medium,0.6161320189263424, https://leetcode.com/problems/lru-cache
|
|
529,Minesweeper,59.1%,Medium,0.42248679567759495, https://leetcode.com/problems/minesweeper
|
|
281,Zigzag Iterator,58.4%,Medium,0.22884157242884745, https://leetcode.com/problems/zigzag-iterator
|
|
200,Number of Islands,46.8%,Medium,0.20236848873924537, https://leetcode.com/problems/number-of-islands
|
|
304,Range Sum Query 2D - Immutable,38.6%,Medium,0.053010091368830885, https://leetcode.com/problems/range-sum-query-2d-immutable
|
|
56,Merge Intervals,39.3%,Medium,0.051732885823426, https://leetcode.com/problems/merge-intervals
|
|
394,Decode String,50.0%,Medium,0.030783500343535258, https://leetcode.com/problems/decode-string
|
|
44,Wildcard Matching,24.7%,Hard,0.029260865212976276, https://leetcode.com/problems/wildcard-matching
|
|
695,Max Area of Island,62.7%,Medium,0.02709377046225989, https://leetcode.com/problems/max-area-of-island
|
|
986,Interval List Intersections,67.3%,Medium,0.025555053351030123, https://leetcode.com/problems/interval-list-intersections
|
|
23,Merge k Sorted Lists,40.2%,Hard,0.023981964686485415, https://leetcode.com/problems/merge-k-sorted-lists
|
|
79,Word Search,35.6%,Medium,0.014673179500416637, https://leetcode.com/problems/word-search
|
|
63,Unique Paths II,34.6%,Medium,0.008375258336732413, https://leetcode.com/problems/unique-paths-ii
|
|
36,Valid Sudoku,48.7%,Medium,0.0069420618952821065, https://leetcode.com/problems/valid-sudoku
|