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)
```
13 lines
1.3 KiB
CSV
13 lines
1.3 KiB
CSV
ID,Title,Acceptance,Difficulty,Frequency,Leetcode Question Link
|
|
593,Valid Square,43.1%,Medium,0.8850660255420153, https://leetcode.com/problems/valid-square
|
|
647,Palindromic Substrings,60.6%,Medium,0.5969293308834104, https://leetcode.com/problems/palindromic-substrings
|
|
203,Remove Linked List Elements,38.6%,Easy,0.30879263622480546, https://leetcode.com/problems/remove-linked-list-elements
|
|
730,Count Different Palindromic Subsequences,41.8%,Hard,0.26866680633829343, https://leetcode.com/problems/count-different-palindromic-subsequences
|
|
716,Max Stack,42.6%,Easy,0.04103139667786253, https://leetcode.com/problems/max-stack
|
|
75,Sort Colors,47.3%,Medium,0.02953900967923939, https://leetcode.com/problems/sort-colors
|
|
155,Min Stack,44.5%,Easy,0.010200700488022775, https://leetcode.com/problems/min-stack
|
|
380,Insert Delete GetRandom O(1),47.5%,Medium,0.00934149716911291, https://leetcode.com/problems/insert-delete-getrandom-o1
|
|
202,Happy Number,50.4%,Easy,0.0059889383976452016, https://leetcode.com/problems/happy-number
|
|
167,Two Sum II - Input array is sorted,54.1%,Easy,0.005280540323033287, https://leetcode.com/problems/two-sum-ii-input-array-is-sorted
|
|
5,Longest Palindromic Substring,29.5%,Medium,0.0048918458243339055, https://leetcode.com/problems/longest-palindromic-substring
|