-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathleetcode.html
237 lines (221 loc) · 8.06 KB
/
leetcode.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LeetCode Problems - DSA Problem Solutions</title>
<link
href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap"
rel="stylesheet"
/>
<link
href="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.min.css"
rel="stylesheet"
/>
<link
href="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/theme-github.min.css"
rel="stylesheet"
/>
<link rel="stylesheet" href="leetcode.css" />
</head>
<body>
<div id="cursor"></div>
<header>
<a href="../index.html" class="logo">
<img src="img/lightlogo.png" alt="Logo" />
</a>
<h1>LeetCode Problems</h1>
</header>
<div class="container">
<div class="problems-list">
<h2>Problems</h2>
<div class="card">
<div class="card-header">
<h3 class="card-title">Two Sum</h3>
</div>
<div class="card-content">
<p>Difficulty: Easy</p>
<div class="button-container">
<button
class="button button-primary"
onclick="handleViewSolution('Two Sum')"
>
<span class="icon">▶</span> View Solution
</button>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<h3 class="card-title">Reverse Linked List</h3>
</div>
<div class="card-content">
<p>Difficulty: Medium</p>
<div class="button-container">
<button
class="button button-primary"
onclick="handleViewSolution('Reverse Linked List')"
>
<span class="icon">▶</span> View Solution
</button>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<h3 class="card-title">Binary Tree Level Order Traversal</h3>
</div>
<div class="card-content">
<p>Difficulty: Medium</p>
<div class="button-container">
<button
class="button button-primary"
onclick="handleViewSolution('Binary Tree Level Order Traversal')"
>
<span class="icon">▶</span> View Solution
</button>
</div>
</div>
</div>
</div>
<div class="solution-display">
<h2>Solution</h2>
<div id="solution-content">
<p>Select a problem to view its solution.</p>
</div>
</div>
<!-- progress card -->
<div class="progress-card">
<h2>Check Your Progress</h2>
<label for="username">Enter your LeetCode username:</label>
<input
type="text"
id="username"
name="username"
placeholder="Username"
required
/>
<button id="fetchButton" class="button button-primary">
Get Progress
</button>
<div id="stats">
<p>✨ Easy: <span id="easy">0</span></p>
<p>⚡ Medium: <span id="medium">0</span></p>
<p>🔥 Hard: <span id="hard">0</span></p>
</div>
</div>
</div>
<!-- Adding question -->
<div class="container">
<div class="problems-list">
<h2 style="font-size: 1.5rem; font-weight: 600; margin-bottom: 20px;">Problems</h2>
<!-- Problem Cards -->
<div id="problems-container"></div>
<!-- Form to Add New Question -->
<div class="ques-form">
<h3 style="margin-top: 20px;">Add a New Question</h3>
<form id="add-problem-form">
<label for="title">Question Title:</label>
<input type="text" id="title" name="title" required style="width: 100%; margin-bottom: 10px;">
<label for="difficulty">Difficulty Level:</label>
<select id="difficulty" name="difficulty" required style="width: 100%; margin-bottom: 10px;">
<option value="Easy">Easy</option>
<option value="Medium">Medium</option>
<option value="Hard">Hard</option>
</select>
<label for="solution">Solution (Code):</label>
<textarea id="solution" name="solution" rows="5" required style="width: 100%; margin-bottom: 10px;"></textarea>
<button type="submit" style="padding: 10px 15px;">Add Question</button>
</form>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js"
integrity="sha512-7eHRwcbYkK4d9g/6tD/mhkf++eoTHwpNM9woBxtPUBWm67zeAfFC+HrdoE2GanKeocly/VxeLvIqwvCdk7qScg=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script src="leetcode.js"></script>
<script>
const problems = [
{
title: "Two Sum",
difficulty: "Easy",
solution: `
<pre><code class="language-python">def two_sum(nums, target):
seen = {}
for i, num in enumerate(nums):
diff = target - num
if diff in seen:
return [seen[diff], i]
seen[num] = i
</code></pre>`
},
{
title: "Reverse Linked List",
difficulty: "Medium",
solution: `
<pre><code class="language-python">class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def reverse_linked_list(head):
prev = None
current = head
while current:
next_node = current.next
current.next = prev
prev = current
current = next_node
return prev
</code></pre>`
}
];
const problemsContainer = document.getElementById('problems-container');
const solutionContent = document.getElementById('solution-content');
const addProblemForm = document.getElementById('add-problem-form');
// Render all questions
function renderProblems() {
problemsContainer.innerHTML = ""; // Clear the container
problems.forEach((problem, index) => {
const card = document.createElement('div');
card.className = 'card';
card.style.marginBottom = "15px"; // Ensure spacing between cards
card.innerHTML = `
<div class="card-header">
<h3 class="card-title">${problem.title}</h3>
</div>
<div class="card-content">
<p>Difficulty: ${problem.difficulty}</p>
<div class="button-container">
<button class="button button-primary" onclick="showSolution(${index})">
<span class="icon">▶</span> View Solution
</button>
</div>
</div>
`;
problemsContainer.appendChild(card);
});
}
// Show solution in the solution display
function showSolution(index) {
const selectedProblem = problems[index];
solutionContent.innerHTML = selectedProblem.solution;
Prism.highlightAll(); // Highlight syntax
}
// Add a new problem from the form
addProblemForm.addEventListener('submit', (e) => {
e.preventDefault();
const title = document.getElementById('title').value;
const difficulty = document.getElementById('difficulty').value;
const solution = `<pre><code class="language-python">${document.getElementById('solution').value}</code></pre>`;
problems.push({ title, difficulty, solution });
renderProblems(); // Re-render the problems list
addProblemForm.reset(); // Clear the form
});
// Initial rendering of problems
renderProblems();
</script>
</body>
</html>