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)
```
14 lines
1.3 KiB
CSV
14 lines
1.3 KiB
CSV
ID,Title,Acceptance,Difficulty,Frequency,Leetcode Question Link
|
|
736,Parse Lisp Expression,47.5%,Hard,1.0065947176467498, https://leetcode.com/problems/parse-lisp-expression
|
|
381,Insert Delete GetRandom O(1) - Duplicates allowed,34.1%,Hard,0.6946505634539769, https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed
|
|
695,Max Area of Island,62.7%,Medium,0.5227168031344483, https://leetcode.com/problems/max-area-of-island
|
|
380,Insert Delete GetRandom O(1),47.5%,Medium,0.2107726489416756, https://leetcode.com/problems/insert-delete-getrandom-o1
|
|
362,Design Hit Counter,63.7%,Medium,0.14310084364067333, https://leetcode.com/problems/design-hit-counter
|
|
49,Group Anagrams,56.9%,Medium,0.08712516204977415, https://leetcode.com/problems/group-anagrams
|
|
42,Trapping Rain Water,48.9%,Hard,0.08028083126080282, https://leetcode.com/problems/trapping-rain-water
|
|
127,Word Ladder,29.6%,Medium,0.06804400933142625, https://leetcode.com/problems/word-ladder
|
|
200,Number of Islands,46.8%,Medium,0.05455898425043439, https://leetcode.com/problems/number-of-islands
|
|
1,Two Sum,45.6%,Easy,0.04327015683483566, https://leetcode.com/problems/two-sum
|
|
322,Coin Change,35.5%,Medium,0.023903996947661692, https://leetcode.com/problems/coin-change
|
|
230,Kth Smallest Element in a BST,60.2%,Medium,0.006085520073802784, https://leetcode.com/problems/kth-smallest-element-in-a-bst
|