990. Satisfiability of Equality Equations Medium

@problem@discussion
#Array#String#Union Find#Graph



1/**
2 * [990] Satisfiability of Equality Equations
3 *
4 * You are given an array of strings equations that represent relationships between variables where each string equations[i] is of length 4 and takes one of two different forms: "xi==yi" or "xi!=yi".Here, xi and yi are lowercase letters (not necessarily different) that represent one-letter variable names.
5 * Return true if it is possible to assign integers to variable names so as to satisfy all the given equations, or false otherwise.
6 *  
7 * Example 1:
8 * 
9 * Input: equations = ["a==b","b!=a"]
10 * Output: false
11 * Explanation: If we assign say, a = 1 and b = 1, then the first equation is satisfied, but not the second.
12 * There is no way to assign the variables to satisfy both equations.
13 * 
14 * Example 2:
15 * 
16 * Input: equations = ["b==a","a==b"]
17 * Output: true
18 * Explanation: We could assign a = 1 and b = 1 to satisfy both equations.
19 * 
20 *  
21 * Constraints:
22 * 
23 * 	1 <= equations.length <= 500
24 * 	equations[i].length == 4
25 * 	equations[i][0] is a lowercase letter.
26 * 	equations[i][1] is either '=' or '!'.
27 * 	equations[i][2] is '='.
28 * 	equations[i][3] is a lowercase letter.
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/satisfiability-of-equality-equations/
34// discuss: https://leetcode.com/problems/satisfiability-of-equality-equations/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn equations_possible(equations: Vec<String>) -> bool {
40        false
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_990() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.