We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4d5d17e commit 67760f1Copy full SHA for 67760f1
990-satisfiability-of-equality-equations.js
@@ -0,0 +1,23 @@
1
+/**
2
+ * @param {string[]} equations
3
+ * @return {boolean}
4
+ */
5
+const equationsPossible = function(equations) {
6
+ const uf = new Array(26).fill(0);
7
+ const aCode = ('a').charCodeAt(0)
8
+
9
+ for (let i = 0; i < 26; ++i) uf[i] = i;
10
+ for (let e of equations)
11
+ if (e.charAt(1) === '=')
12
+ uf[find(e.charCodeAt(0) - aCode)] = find(e.charCodeAt(3) - aCode);
13
14
+ if (e.charAt(1) === '!' && find(e.charCodeAt(0) - aCode) === find(e.charCodeAt(3) - aCode))
15
+ return false;
16
+ return true;
17
18
19
+ function find(x) {
20
+ if (x != uf[x]) uf[x] = find(uf[x]);
21
+ return uf[x];
22
+ }
23
+};
0 commit comments