Cover image for leetcode每日一题 P2169 得到 0 的操作数

leetcode每日一题 P2169 得到 0 的操作数

字数 96
阅读
访客

时间轴

时间轴

2025-11-09

init

模拟

题目:

周末奖励题

12345678910111213141516
#include <algorithm>class Solution {    public:	int countOperations(int num1, int num2)	{		int ops = 0;		while (num1 != 0 && num2 != 0) {			if (num1 < num2) { //num1为较大的那个				std::swap(num1, num2);			}			num1 = num1 - num2;			ops++;		}		return ops;	}};
评论加载中…