1385.两个数组间的距离值
https://leetcode-cn.com/problems/find-the-distance-value-between-two-arrays/
while for if 循环给人的感觉就是层层深入,先深入for这层循环然后再对条件进行分析,再依次深入下一层循环。
//感觉就是步步深入的那种感觉,先用for在这个循环然后再深入到for这个循环里面
int findTheDistanceValue(int* arr1, int arr1Size, int* arr2, int arr2Size, int d){
int i,j,num=0;
for(i=0;i<arr1Size;i++) //两次遍历
{
for(j=0;j<arr2Size;j++)
{
if(abs(arr1[i]-arr2[j])>d)
{
if(j==arr2Size-1) //在(abs(arr1[i]-arr2[j])>d)中直接去寻找
//j==arr2Size-1 成立的话说明前面的都成立
{
num++;
}
}else break; //注意break
}
}return num;
}
1291.顺次数
https://leetcode-cn.com/problems/sequential-digits/
打表出符合顺次数的并放在一个数组内
int a[]={12,23,34,45,56,67,78,89,
123,234,345,456,567,678,789,
1234,2345,3456,4567,5678,6789,
12345,23456,34567,45678,56789,
123456,234567,345678,456789,
1234567,2345678,3456789,
12345678,23456789,
123456789};
int* sequentialDigits(int low, int high, int* returnSize){
int *res=malloc(sizeof(int)*36); //malloc 分配数组内存大小
int count=0;
for(int i=0;i<36;i++)
{
if((a[i]>=low)&&a[i]<=high)
{
res[count++]=a[i];
}
} *returnSize=count; //*returnSize 一定要精准 这里*returnSize=count;
// 表示输出值的个数为count
return res;
}
2048.下一个更大的数值平衡数
https://leetcode-cn.com/problems/next-greater-numerically-balanced-number/
打表出符合条件的并放在一个数组内
int a[]={ 1,22, 122, 212, 221, 333, 1333, 3133, 3313, 3331, 4444, 14444, 22333, 23233, 23323, 23332, 32233, 32323, 32332, 33223, 33232, 33322, 41444, 44144, 44414, 44441, 55555, 122333, 123233, 123323, 123332, 132233, 132323, 132332, 133223, 133232, 133322, 155555, 212333, 213233, 213323, 213332, 221333, 223133, 223313, 223331, 224444, 231233, 231323, 231332, 232133, 232313, 232331, 233123, 233132, 233213, 233231, 233312, 233321, 242444, 244244, 244424, 244442, 312233, 312323, 312332, 313223, 313232, 313322, 321233, 321323, 321332, 322133, 322313, 322331, 323123, 323132, 323213, 323231, 323312, 323321, 331223, 331232, 331322, 332123, 332132, 332213, 332231, 332312, 332321, 333122, 333212, 333221, 422444, 424244, 424424, 424442, 442244, 442424, 442442, 444224, 444242, 444422, 515555, 551555, 555155, 555515, 555551, 666666, 1224444};
int nextBeautifulNumber(int n){
for(int i=0;i<sizeof(a)/4;i++) //int数据类型占四个字节,所以需要除以4
{
if(a[i]>n)return a[i]; //注意是严格大于n的不包括n
}return 0;
}