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)
```
21 lines
2.1 KiB
CSV
21 lines
2.1 KiB
CSV
ID,Title,Acceptance,Difficulty,Frequency,Leetcode Question Link
|
|
312,Burst Balloons,51.8%,Hard,0.05677042474639432, https://leetcode.com/problems/burst-balloons
|
|
32,Longest Valid Parentheses,28.4%,Hard,0.03477099521294092, https://leetcode.com/problems/longest-valid-parentheses
|
|
85,Maximal Rectangle,37.7%,Hard,0.012771565679487524, https://leetcode.com/problems/maximal-rectangle
|
|
523,Continuous Subarray Sum,24.6%,Medium,0.011293174793455513, https://leetcode.com/problems/continuous-subarray-sum
|
|
572,Subtree of Another Tree,44.1%,Easy,0.010042765802138606, https://leetcode.com/problems/subtree-of-another-tree
|
|
18,4Sum,33.7%,Medium,0.009345862418237686, https://leetcode.com/problems/4sum
|
|
876,Middle of the Linked List,68.4%,Easy,0.007282027445765432, https://leetcode.com/problems/middle-of-the-linked-list
|
|
190,Reverse Bits,39.8%,Easy,0.007245095991891571, https://leetcode.com/problems/reverse-bits
|
|
31,Next Permutation,32.6%,Medium,0.005748794217024406, https://leetcode.com/problems/next-permutation
|
|
127,Word Ladder,29.6%,Medium,0.005731495844689608, https://leetcode.com/problems/word-ladder
|
|
5,Longest Palindromic Substring,29.5%,Medium,0.0048918458243339055, https://leetcode.com/problems/longest-palindromic-substring
|
|
22,Generate Parentheses,62.7%,Medium,0.004152398782798953, https://leetcode.com/problems/generate-parentheses
|
|
1,Two Sum,45.6%,Easy,0.003139596786381058, https://leetcode.com/problems/two-sum
|
|
33,Search in Rotated Sorted Array,34.5%,Medium,0.0031000567336666443, https://leetcode.com/problems/search-in-rotated-sorted-array
|
|
20,Valid Parentheses,39.0%,Easy,0.002197682330605871, https://leetcode.com/problems/valid-parentheses
|
|
21,Merge Two Sorted Lists,53.5%,Easy,0.002158080146984904, https://leetcode.com/problems/merge-two-sorted-lists
|
|
15,3Sum,26.8%,Medium,0.002081166203824567, https://leetcode.com/problems/3sum
|
|
103,Binary Tree Zigzag Level Order Traversal,48.3%,Medium,0.0016881202574030904, https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal
|
|
3,Longest Substring Without Repeating Characters,30.4%,Medium,0.0014852223137141987, https://leetcode.com/problems/longest-substring-without-repeating-characters
|