leetcode8 字符串转换为整数()

 不要看我的,由于开始的时候没有看懂题目的要求,导致代码改了又改,简直是面向测试编程,有空我把代码重构一下。

int belong_to(char c,char *mys){
    int j;
    char *ss = mys;

    int slen=0;
    slen = strlen(ss);

    for(j=0;j < slen;j++){
        if(c == ss[j]){
            return 1;
        }
    }
    return 0;
}

int myAtoi(char * s){
    char use[] = "+- 0123456789\0";//{'+','-',' ','0','1','2','3','4','5','6','7','8','9'};
    char hh[] = "0123456789\0";//{'0','1','2','3','4','5','6','7','8','9'};
    char tt[] = "+-\0";
    int64_t value=0;
    int Min = -pow(2,31);
    int k;
    

    int Max = pow(2,31) -1 ;
    char t[200]= {'\0'};
    int slen = strlen(s);
    if(slen == 0){
        return 0;
    }
    for(k=0;k 1){
        for(i = 0;i=2){
            return 0;
        }

    }
    if(k>=1){
        if(start -1> 0){
            if(t[start-1] = " ")
                return 0;
        }
    }
    
    if(start>0&&t[start-1]=='-'){
        flag = 1;

    }
    printf("statt%d\n",start);
    for(i = start;i=4294967296){
            if(flag){
                return Min;
            }
            else{
                return Max;
            }
        }
        value = value*10 +j;
        printf("value = %ld",value);
   
    }
    if(value > Max){
        printf("jjjjj\n");
        if(flag){
            
            printf("jjhhhhhhh\n");
            return Min;
        }
        else{
            return Max;
        }
    }
    else{
        if(flag){
            return -(int)value;
        }
        else 
            return value;
    }
}

你可能感兴趣的:(LeetCode,算法,c语言,leetcode)