leetCode6.ZigZagConversion字符串(上传费劲)-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

leetCode6.ZigZagConversion字符串(上传费劲)

6. ZigZag Conversion

创新互联是专业的恩平网站建设公司,恩平接单;提供做网站、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行恩平网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

题目:https://leetcode.com/problems/zigzag-conversion/

string convert2(string s, int numRows) {
	if (s.length() < 2 || numRows < 2)
		return s;
	int cycle = 2 * numRows - 2;
	string tmp;
	string result;
	for (int i = 0; i < numRows; i++)
	{
		if (i == 0 || i == numRows - 1)
		{
			for (int j = 0; j < s.length(); j += cycle)
			{
				if (i + j < s.length())
					tmp += s.at(i+j);
			}
			result += tmp;
			cout << tmp << endl;
			tmp.clear();
		}
		else
		{
			int minus = numRows - i - 1;
			int j, j1;
			bool find = false;
			for (j = i, j1 = 0; j < s.length(); j += cycle, j1 += cycle)
			{
				tmp += s.at(j);
				if (!find)
				{
					j1 = j + 2 * minus;
				}
				
				if (j1 < s.length())
					tmp += s.at(j1);
			}
			result += tmp;
			cout << tmp << endl;
			tmp.clear();
		}
	}
	return result;
}

2016-08-08 20:30:52


文章标题:leetCode6.ZigZagConversion字符串(上传费劲)
网站链接:http://kswsj.cn/article/pgoics.html

其他资讯