zoukankan      html  css  js  c++  java
  • 【leetcode】强整数

    int cmp(const void* a, const void* b)
    {
        return *(int*)a - *(int*)b;
    }
    int* powerfulIntegers(int x, int y, int bound, int* returnSize){
        if (bound<2)
        {
            *returnSize = 0;
            return NULL;
        }
        int* arr = (int*)calloc(bound,sizeof(int));
        int i,j,xMax=1,yMax=1,n=0,m=1;
        if (x !=1)
        {
            for (i=1; i<=bound && pow(x,i)<=bound; i++);  //找出x对应次方的最大范围
            xMax = i;
        }
        if (y != 1)
        {
            for (i=1; i<=bound && pow(y,i)<=bound; i++);  //找出y对应次方的最大范围
            yMax=i;
        }
        for (i=0; i<xMax; i++)
        {
            for (j=0; j<yMax && pow(x,i) + pow(y,j) <= bound; j++)
            {
                arr[n++] = pow(x,i) + pow(y,j);
            }
        }
        qsort(arr,n,sizeof(int),cmp);
        for (i=1; i<n; i++)
        {
            if (arr[i] != arr[i-1]) arr[m++] = arr[i]; //去掉重复的数
        }
        *returnSize = m;
        return arr;
    }
  • 相关阅读:
    盒子模型中问题
    outline
    高度自动相等方法
    正则表达式
    绝对定位 相对定位
    replace 使用函数作为第二参数
    float 浮动
    line-height 行高
    元素隐藏
    现代浏览器内部
  • 原文地址:https://www.cnblogs.com/ganxiang/p/13651991.html
Copyright © 2011-2022 走看看