经典指数          
原因
1143
浏览数
0
收藏数
 

The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line:"PAHNAPLSIIGYIR" Write the code that will take a string and make this conversion given a number of rows: string convert(string text, int nRows); convert("PAYPALISHIRING", 3)should return"PAHNAPLSIIGYIR".

     举报   纠错  
 
切换
1 个答案
//题目还是小伙伴解释才看懂。。。输入的数组digits表示一个大整数,每个表示一位。 class Solution { public: vector plusOne(vector &digits) { const int num = 1; //待加数 int carry = num; //进位 for (int i = digits.size() - 1; i >= 0; i--) { digits[i] += carry; carry = digits[i] / 10; digits[i] %= 10; } if (carry > 0) digits.insert(digits.begin(),1); return digits; } };
 
切换
撰写答案
扫描后移动端查看本题