#990
Satisfiability of Equality Equations
specialist · 840 · lc medium +31 · verified · 51.6% accepted · 4,010 likes · top 41%
Description
You are given an array of strings equations where each string has length 4 and takes the form "xi==yi" or "xi!=yi", with xi and yi being single lowercase letters representing one-variable names.
Return true if there exists an integer assignment to the variables satisfying every equation, or false otherwise.
Example 1:
Input: equations = ["a==b","b!=a"]
Output: false
Explanation: If we assign say, a = 1 and b = 1, then the first equation is satisfied, but not the second.
There is no way to assign the variables to satisfy both equations.
Example 2:
Input: equations = ["b==a","a==b"]
Output: true
Explanation: We could assign a = 1 and b = 1 to satisfy both equations.
Code
1
2
3