【leetcode】写字符串需要的行数

int* numberOfLines(int* widths, int widthsSize, char * S, int* returnSize){
    int i=0,row=1,total=0,len = strlen(S);
    int* arr = (int*)calloc(2,sizeof(int));
    for (; i<len; i++)
    {
        total += widths[S[i] - 'a'];
        if (total > 100)
        {
            row++;
            total = widths[S[i] - 'a'];
        }
    }
    arr[0] = row;
    arr[1] = total;
    *returnSize = 2;
    return arr;
}
原文地址:https://www.cnblogs.com/ganxiang/p/13665623.html