Skip to content

Commit f6b8419

Browse files
authored
Create build-the-equation.sql
1 parent e86c026 commit f6b8419

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

MySQL/build-the-equation.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(nlogn)
2+
# Space: O(n)
3+
4+
SELECT
5+
CONCAT(
6+
GROUP_CONCAT(
7+
CASE
8+
WHEN factor > 0 THEN CONCAT('+', factor)
9+
ELSE factor
10+
END,
11+
CASE
12+
WHEN power=0 THEN ''
13+
WHEN power=1 THEN 'X'
14+
ELSE CONCAT('X^', power)
15+
END
16+
ORDER BY power DESC SEPARATOR ''), '=0') AS equation
17+
FROM Terms;

0 commit comments

Comments
 (0)