leetcode zigzag conversion
来源:互联网 发布:java反斜杠替换 编辑:程序博客网 时间:2024/05/15 04:35
一开始实在没看懂题意。。。。 只好找找啥意思,结果一下就看到答案了,哎。
不过还是用了50行代码。看看人家,十几行搞定,真是惭愧- -
leetcode上的代码:
class Solution{public: string convert(string s, int nRows) { if(nRows < 2 || s.length() <= nRows) return s; string ret = ""; for(int row=0; row<nRows; row++){ if(row == 0 || row == nRows-1){ int step = 2*nRows-2; int index = row; while(index < s.length()){ ret.push_back(s[index]); index += step; } }else{ int step = 2*nRows-2; int index = row; while(index < s.length()){ ret.push_back(s[index]); int zig_index = index + (step - 2*row); if(zig_index < s.length()) ret.push_back(s[zig_index]); index += step; } } } return ret; }};
0 0
- LeetCode: ZigZag Conversion
- LeetCode : ZigZag Conversion
- leetcode 13:zigzag conversion
- [LeetCode] Zigzag Conversion
- LeetCode 6 - ZigZag Conversion
- Leetcode : ZigZag Conversion
- 【leetcode】Zigzag Conversion
- [LeetCode]ZigZag Conversion
- leetcode ZigZag Conversion
- LeetCode-ZigZag Conversion
- LeetCode ZigZag Conversion
- LeetCode 6: ZigZag Conversion
- leetcode-006:ZigZag Conversion
- Leetcode: ZigZag Conversion
- [LeetCode]ZigZag Conversion
- [LeetCode] ZigZag Conversion
- [LeetCode]ZigZag Conversion
- leetcode: ZigZag Conversion
- POJ1511——Invitation Cards
- BZOJ 1650: [Usaco2006 Dec]River Hopscotch 跳石子
- POJ2253——Frogger
- NOJ——[1579] 小青蛙找妈妈
- 剑指offer-29:数组中出现次数超过一半的数字
- leetcode zigzag conversion
- zoj 1453 Surround the Trees (求凸包的周长)
- 如何确保你的远程员工有效地开展工作
- Embarcadero RAD Studio XE6 编译器可能是最大的编译器。
- javaScript学习日志 2014-8-5
- 一步一步教会你JAVA中调用C++
- 使用Eclipse Ant plugin操作流程
- 如何破解瞻博网络认证的互联网专家 - JUNOS安全考试(JNCIS)
- ScheduledExecutorService定时任务