Submission Details
2016-02-23 13:14
417 查看
我是把它看作是“W”型字,并且“V”作为一个处理循环
提交后错了两次:第一次内存预设不够大100变为1000
第二次没考虑边界情况,当输出行为1时,可以不用处理直接输出
124ms,是比较慢的
优化的话:可以把二维字符数组改为一维字符串数组,这样最后不用在循环重新获取一边。
提交后错了两次:第一次内存预设不够大100变为1000
第二次没考虑边界情况,当输出行为1时,可以不用处理直接输出
class Solution { public: string convert(string s, int numRows) { char ischar[1000][1000]={0}; int cer_i=0; int col=0,i=0; string change; if(numRows==1) return s; while(i<s.length()) { while(cer_i<numRows && i<s.length()) ischar[cer_i++][col]=s[i++]; cer_i=cer_i-2; while(cer_i>0 && i<s.length()) ischar[cer_i--][++col]=s[i++]; col++; if(i>=s.length()) break; } for(int m=0;m<numRows;m++) for(int n=0;n<col;n++) { if(ischar[m] !=0) change=change+ischar[m] ; } return change; } };
124ms,是比较慢的
优化的话:可以把二维字符数组改为一维字符串数组,这样最后不用在循环重新获取一边。
相关文章推荐
- http://blog.csdn.net/limingchuan123456789/article/details/16849897
- 'hibernate.dialect' must be set when no Connection available
- 24-题目1436:Repair the Wall
- Paint类
- Jenkins进阶系列之——02email-ext邮件通知模板
- 关于 “does not contain bitcode.”的错误解决办法
- WindowsAPI - Net - WSAStartup - Baidu.com
- process launch failed: Security
- tools:context=".MainActivity的作用
- poj2010 Moo University - Financial Aid
- VS2008启动时提示“Package load failure”
- waiting for X server to shut down Server terminated successfully(0) ,closing log file
- AIDL service纪事 注意事项
- 人工智能 有限状态机 的时代过去了
- could not obtain the localhost address
- Rails 中的事物处理
- Maven-010-maven 编译报错:Failure to ... in ... was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced.
- 可执行程序的入口点在那里?(强化概念:程序真正的入口是mainCRTstartup)
- Educational Codeforces Round 8 F. Bear and Fair Set(最大流 | Hall定理)
- POJ1704--Georgia and Bob--staircase nim