38. 报数
int和char类型转换
int num=2;
char c=(char)(num+'0');
char c='2';
int n=(int )(c-'0');
char * countAndSay(int n){
char *newstr=malloc(200*n);
int k=0;
if(n==1){
return "1";
}
else{
char *str=countAndSay(n-1);
for(int i=0;i<strlen(str);i++){
if(str[i]!=str[i+1])
{
newstr[k++]='1';
newstr[k++]=str[i];
}
else {
int count=1;
count++;
while((i+count<strlen(str))&&(str[i]==str[i+count])){
count++;
}
char c=(char)(count+'0');
newstr[k++]=c;
newstr[k++]=str[i];
i=i+count-1;
}
}
newstr[k]='\0';
}
return newstr;
}
41. 缺失的第一个正数
int firstMissingPositive(int* nums, int numsSize){
int len=numsSize+1;
int flag[1024]={0};
for(int i=0;i<numsSize;i++){
if(nums[i]<=numsSize&&nums[i]>0)
flag[nums[i]]=1;
}
int j;
for(j=1;j<=numsSize;j++){
if(flag[j]==0) break;
}
return j;
}