Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7d63c70

Browse files
Added solution from database.
1 parent 2b5ed84 commit 7d63c70

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

‎src/app/questions/[qid]/SolutionShowcase.jsx‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,11 @@ import CodeMirror from "@uiw/react-codemirror";
55
import { python } from "@codemirror/lang-python";
66
import { EditorView } from "@codemirror/view";
77
import { githubDark } from "@uiw/codemirror-theme-github";
8-
function SolutionShowcase() {
9-
const code = `class Solution:
10-
11-
def twoSum_bruteforce(self, nums: list[int], target: int) -> list[int]:
12-
for i, num1 in enumerate(nums):
13-
for j, num2 in enumerate(nums):
14-
if i != j and num1+num2==target:
15-
return [i, j]
16-
17-
def twoSum(self, nums: list[int], target: int) -> list[int]:
18-
indices = {}
19-
for i, num in enumerate(nums):
20-
indices[num] = i
21-
for i, num in enumerate(nums):
22-
if target - num in indices and indices[target - num] != i:
23-
return [i, indices[target-num]]`;
8+
function SolutionShowcase({ solutionsString }) {
249
return (
2510
<div>
2611
<CodeMirror
27-
value={code}
12+
value={solutionsString}
2813
extensions={[python({}), EditorView.lineWrapping]}
2914
theme={githubDark}
3015
readOnly={true}

‎src/app/questions/[qid]/SolutionWrapper.jsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import SolutionShowcase from "./SolutionShowcase";
22

3-
export const SolutionWrapper = () => {
3+
export const SolutionWrapper = ({ solutions, codeStub }) => {
4+
const solutionsCombined = solutions.map(({ code }) => code);
5+
const solutionsString =
6+
solutions.length > 0
7+
? `class Solution:
8+
${solutionsCombined.join("\n")}`
9+
: codeStub;
410
return (
511
<div className="w-full h-full overflow-x-hidden justify-items-start mb-10">
612
<div className="font-bold text-left mb-2">Solutions</div>
713
<div className="font-bold text-left mb-2">
8-
<SolutionShowcase />
14+
<SolutionShowcase solutionsString={solutionsString}/>
915
</div>
1016
</div>
1117
);

‎src/app/questions/[qid]/page.jsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export default async function QuestionsPage({ params: { qid } }) {
2626
similarQuestions={similarQuestions}
2727
topicTags={data[0]["topicTags"]}
2828
/>
29-
<SolutionWrapper />
29+
<SolutionWrapper
30+
solutions={data[0].solutions}
31+
codeStub={data[0].Code}
32+
/>
3033
</div>
3134
)}
3235
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /