leetcode--Z字形变换
2019-03-28 10:42
337 查看
解题思路:
根据规律编号,发现行数和各字符行号之间的规律
代码:
根据规律编号,发现行数和各字符行号之间的规律
![](https://img-blog.csdnimg.cn/20190328104213831.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2JhaWR1XzI3NTE4ODI5,size_16,color_FFFFFF,t_70)
代码:
char* convert(char* s, int numRows) { int len = strlen(s); char *r = (char*)malloc(sizeof(int)*(len+1)); int p = 0; if(numRows==1) return s; for(int k = 0;k < numRows;k++) { for(int j = 0;j < len;j++) { int m = j%(numRows*2-2); if(m==k||(numRows*2-2)-m==k) { r[p] = s[j]; p++; } } } r[len] = '\0'; return r; }
相关文章推荐
- LeetCode6.python实现:Z 字形变换问题☆☆
- leetcode-6倒转Z 字形变换
- LeetCode6. Z 字形变换
- LeetCode-6 : Z 字形变换 ★★★
- Z 字形变换(LeetCode)
- Leetcode(C++)——6. Z 字形变换
- LeetCode第6题--Z 字形变换
- 【Leetcode】6.Z字形变换
- @LeetCodeZ字形变换--ZigZag Conversion[C++]
- leetCode第6题,Z字形变换
- 【LeetCode】之字形变换
- LeetCode 6 Z字形变换(字符串)
- 【leetcode】Zigzag Z 字形变换
- leetcode 6. Z 字形变换(Java版)
- Z字形变换 - LeetCode
- LeetCode 6.Z 字形变换
- LeetCode题解(python)-6. Z 字形变换
- 基础算法之Z字形变换(Leetcode-6)
- leetcode Z 字形变换
- LeetCode | 6. ZigZag Conversion(之字形变换)