Skip to content

Commit b983c60

Browse files
add 990
1 parent f50ecd7 commit b983c60

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,5 @@ LeetCode
321321
|0986|[Interval List Intersections](https://leetcode.com/problems/interval-list-intersections/) | c | [c++](./src/0986-Interval-List-Intersections/0986.cpp) |[python](./src/0986-Interval-List-Intersections/0986.py)|||Medium|
322322
|0987|[Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/) | c | [c++](./src/0987-Vertical-Order-Traversal-of-a-Binary-Tree/0987.cpp) |[python](./src/0987-Vertical-Order-Traversal-of-a-Binary-Tree/0987.py)|||Medium|
323323
|0988|[Smallest String Starting From Leaf](https://leetcode.com/problems/smallest-string-starting-from-leaf/) | c | [c++](./src/0988-Smallest-String-Starting-From-Leaf/0988.cpp) |[python](./src/0988-Smallest-String-Starting-From-Leaf/0988.py)|||Medium|
324-
|0989|[Add to Array-Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer/) | c | [c++](./src/0989-Add-to-Array-Form-of-Integer/0989.cpp) |[python](./src/0989-Add-to-Array-Form-of-Integer/0989.py)|||Easy|
324+
|0989|[Add to Array-Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer/) | c | [c++](./src/0989-Add-to-Array-Form-of-Integer/0989.cpp) |[python](./src/0989-Add-to-Array-Form-of-Integer/0989.py)|||Easy|
325+
|0990|[Satisfiability of Equality Equations](https://leetcode.com/problems/satisfiability-of-equality-equations/) | c | [c++](./src/0990-Satisfiability-of-Equality-Equations/0990.cpp) |[python](./src/0990-Satisfiability-of-Equality-Equations/0990.py)|||Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
static int x = [](){std::ios::sync_with_stdio(false);cin.tie(0);return 0;}();
2+
class Solution
3+
{
4+
public:
5+
bool equationsPossible(vector<string>& equations)
6+
{
7+
for (int i = 0; i < 26; ++i) _parents[i] = i;
8+
for (string& e : equations)
9+
{
10+
if (e[1] == '=')
11+
_parents[_find(e[0] - 'a')] = _find(e[3] - 'a');
12+
}
13+
14+
for (string& e : equations)
15+
{
16+
if (e[1] == '!' && _find(e[0] - 'a') == _find(e[3] - 'a'))
17+
return false;
18+
}
19+
return true;
20+
}
21+
private:
22+
int _parents[26];
23+
24+
int _find(int x)
25+
{
26+
if (x != _parents[x]) _parents[x] = _find(_parents[x]);
27+
return _parents[x];
28+
}
29+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def equationsPossible(self, equations: 'List[str]') -> 'bool':
3+
tmp = {chr(i): chr(i) for i in range(97, 125)}
4+
5+
def find(x):
6+
if x != tmp[x]:
7+
tmp[x]= find(tmp[x])
8+
return tmp[x]
9+
10+
for it in equations:
11+
if it[1] == '=':
12+
tmp[find(it[0])] = find(it[-1])
13+
14+
for it in equations:
15+
if it[1] == '!':
16+
if find(it[0]) == find(it[-1]):
17+
return False
18+
return True

0 commit comments

Comments
 (0)