From e1ce93346a3791bcb3c57aef35f031b7175968d1 Mon Sep 17 00:00:00 2001 From: cfngc4594 Date: Thu, 27 Mar 2025 14:10:03 +0800 Subject: [PATCH] feat(seed): add videos, images, and accordion hints for test data --- prisma/seed.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index 281e3ce..3b75ea0 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -71,6 +71,8 @@ You may assume that each input would have **exactly one solution**, and you may You can return the answer in any order. + + ## Examples ### Example 1 @@ -113,10 +115,24 @@ Output: [0,1] Only one valid answer exists. +**Follow-up:** Can you come up with an algorithm that is less than $O(n^2)$ time complexity? + --- -**Follow-up:** Can you come up with an algorithm that is less than $O(n^2)$ time complexity?`, - solution: `## Approach 1: Brute Force + +A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. + + + +So, if we fix one of the numbers, say \`x\`, we have to scan the entire array to find the next number \`y\` which is \`value - x\` where value is the input parameter. Can we change our array somehow so that this search becomes faster? + + + +The second train of thought is, without changing the array, can we use additional space somehow? Like maybe a hash map to speed up the search? +`, + solution: ` + +## Approach 1: Brute Force ### Algorithm @@ -313,6 +329,8 @@ You may assume the two numbers do not contain any leading zero, except the numbe ### Example 1 +![Example 1](https://assets.leetcode.com/uploads/2020/10/02/addtwonumber1.jpg) + \`\`\`shell Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] @@ -352,6 +370,8 @@ It is guaranteed that the list represents a number that does not have leading ze Keep track of the carry using a variable and simulate digits-by-digits sum starting from the head of list, which contains the least-significant digit. +![Figure 1](https://leetcode.com/problems/add-two-numbers/Figures/2_add_two_numbers.svg) + *Figure 1. Visualization of the addition of two numbers: $342 + 465 = 807$.* *Each node contains a single digit and the digits are stored in reverse order.*