2310 个位数字为 K 的整数之和

This commit is contained in:
relative 2025-04-29 03:04:07 +08:00
parent 219b9a0a02
commit 14117c10bb
4 changed files with 28 additions and 1 deletions

View File

@ -249,7 +249,7 @@ vector<string> Solution::summaryRanges(vector<int>& nums) {
#endif
}
vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
vector<vector<int>> Solution::insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
int start = -1;
int end = -1;
for (int i = 0; i < intervals.size(); i++) {
@ -300,4 +300,26 @@ vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInter
intervals.erase(intervals.begin() + i);
}
return intervals;
}
int Solution::minimumNumbers(int num, int k) {
if (num == 0)
return 0;
if (num == k)
return 1;
if (k == 0)
{
if (num >= 10 && num % 10 == 0)
return 1;
else
return -1;
}
int value = 0;
for (int i = 1; i <= 10; i++) {
value += k;
if ((value % 10) == (num % 10) && value <= num)
return i;
}
return -1;
}

View File

@ -33,5 +33,7 @@ public:
vector<string> summaryRanges(vector<int>& nums);
// 57. 插入区间
vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval);
// 2310. 个位数字为 K 的整数之和
int minimumNumbers(int num, int k);
};

View File

@ -1,5 +1,6 @@
#pragma once
#include <string>
#include <vector>
using namespace std;
class ¹þÏ£±í

View File

@ -22,6 +22,8 @@ int main()
//int data[20];
//cout << "data size is " << sizeof(data) << endl;
Solution solution;
solution.minimumNumbers(58, 9);
////vector<int> nums1 = { 1, 2, 3, 0, 0, 0 };
//vector<int> nums2 = { 2, 5, 6 };
//solution.isPalindrome("A man, a plan, a canal: Panama");