1007. Minimum Domino Rotations For Equal Row Medium

@problem@discussion
#Array#Greedy



1/**
2 * [1007] Minimum Domino Rotations For Equal Row
3 *
4 * In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the i^th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
5 * We may rotate the i^th domino, so that tops[i] and bottoms[i] swap values.
6 * Return the minimum number of rotations so that all the values in tops are the same, or all the values in bottoms are the same.
7 * If it cannot be done, return -1.
8 *  
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2021/05/14/domino.png" style="height: 300px; width: 421px;" />
11 * Input: tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2]
12 * Output: 2
13 * Explanation: 
14 * The first figure represents the dominoes as given by tops and bottoms: before we do any rotations.
15 * If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
16 * 
17 * Example 2:
18 * 
19 * Input: tops = [3,5,1,2,3], bottoms = [3,6,3,3,4]
20 * Output: -1
21 * Explanation: 
22 * In this case, it is not possible to rotate the dominoes to make one row of values equal.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	2 <= tops.length <= 2 * 10^4
28 * 	bottoms.length == tops.length
29 * 	1 <= tops[i], bottoms[i] <= 6
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/minimum-domino-rotations-for-equal-row/
35// discuss: https://leetcode.com/problems/minimum-domino-rotations-for-equal-row/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn min_domino_rotations(tops: Vec<i32>, bottoms: Vec<i32>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_1007() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.