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)
```
18 lines
1.8 KiB
CSV
18 lines
1.8 KiB
CSV
ID,Title,Acceptance,Difficulty,Frequency,Leetcode Question Link
|
|
871,Minimum Number of Refueling Stops,31.4%,Hard,0.021853241177366825, https://leetcode.com/problems/minimum-number-of-refueling-stops
|
|
146,LRU Cache,33.2%,Medium,0.017369086240613615, https://leetcode.com/problems/lru-cache
|
|
91,Decode Ways,24.7%,Medium,0.012884931303860403, https://leetcode.com/problems/decode-ways
|
|
72,Edit Distance,44.8%,Hard,0.009571740941281605, https://leetcode.com/problems/edit-distance
|
|
113,Path Sum II,46.7%,Medium,0.009374336284705936, https://leetcode.com/problems/path-sum-ii
|
|
215,Kth Largest Element in an Array,55.4%,Medium,0.00838696557248326, https://leetcode.com/problems/kth-largest-element-in-an-array
|
|
240,Search a 2D Matrix II,43.2%,Medium,0.007279377002901276, https://leetcode.com/problems/search-a-2d-matrix-ii
|
|
33,Search in Rotated Sorted Array,34.5%,Medium,0.006961661779487692, https://leetcode.com/problems/search-in-rotated-sorted-array
|
|
88,Merge Sorted Array,39.4%,Easy,0.006480904084083141, https://leetcode.com/problems/merge-sorted-array
|
|
2,Add Two Numbers,33.9%,Medium,0.006462841091831753, https://leetcode.com/problems/add-two-numbers
|
|
124,Binary Tree Maximum Path Sum,34.3%,Hard,0.005272883295230408, https://leetcode.com/problems/binary-tree-maximum-path-sum
|
|
543,Diameter of Binary Tree,48.4%,Easy,0.005047966297304777, https://leetcode.com/problems/diameter-of-binary-tree
|
|
1,Two Sum,45.6%,Easy,0.004901297870354067, https://leetcode.com/problems/two-sum
|
|
15,3Sum,26.8%,Medium,0.002081166203824567, https://leetcode.com/problems/3sum
|
|
3,Longest Substring Without Repeating Characters,30.4%,Medium,0.0014852223137141987, https://leetcode.com/problems/longest-substring-without-repeating-characters
|
|
70,Climbing Stairs,47.8%,Easy,0.0014753073158671238, https://leetcode.com/problems/climbing-stairs
|