2169. Count Operations to Obtain Zero Easy

@problem@discussion
#Math#Simulation



1/**
2 * [2169] Count Operations to Obtain Zero
3 *
4 * You are given two non-negative integers num1 and num2.
5 * In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.
6 * 
7 * 	For example, if num1 = 5 and num2 = 4, subtract num2 from num1, thus obtaining num1 = 1 and num2 = 4. However, if num1 = 4 and num2 = 5, after one operation, num1 = 4 and num2 = 1.
8 * 
9 * Return the number of operations required to make either num1 = 0 or num2 = 0.
10 *  
11 * Example 1:
12 * 
13 * Input: num1 = 2, num2 = 3
14 * Output: 3
15 * Explanation: 
16 * - Operation 1: num1 = 2, num2 = 3. Since num1 < num2, we subtract num1 from num2 and get num1 = 2, num2 = 3 - 2 = 1.
17 * - Operation 2: num1 = 2, num2 = 1. Since num1 > num2, we subtract num2 from num1.
18 * - Operation 3: num1 = 1, num2 = 1. Since num1 == num2, we subtract num2 from num1.
19 * Now num1 = 0 and num2 = 1. Since num1 == 0, we do not need to perform any further operations.
20 * So the total number of operations required is 3.
21 * 
22 * Example 2:
23 * 
24 * Input: num1 = 10, num2 = 10
25 * Output: 1
26 * Explanation: 
27 * - Operation 1: num1 = 10, num2 = 10. Since num1 == num2, we subtract num2 from num1 and get num1 = 10 - 10 = 0.
28 * Now num1 = 0 and num2 = 10. Since num1 == 0, we are done.
29 * So the total number of operations required is 1.
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	0 <= num1, num2 <= 10^5
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/count-operations-to-obtain-zero/
40// discuss: https://leetcode.com/problems/count-operations-to-obtain-zero/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn count_operations(num1: i32, num2: i32) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2169() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.