LeetCode228——Summary Ranges
来源:互联网 发布:135端口入侵 编辑:程序博客网 时间:2024/05/20 01:12
一个月没写C++代码,现在感到好陌生
Given a sorted integer array without duplicates, return the summary of its ranges.
For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].
Credits: Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
vector<string> summaryRanges(vector<int>& nums) { vector<string> vs; if (nums.size() == 0) return vs; int begin = nums[0]; int end = nums[0]; char temp[256]; for (int i = 1; i < nums.size(); i++){ if (nums[i] != end+1) { if (begin != end) { sprintf(temp, "%d->%d", begin, end); }else { sprintf(temp, "%d",end); } string s(temp); vs.push_back(s); begin = nums[i]; } end = nums[i]; } if (begin != end) { sprintf(temp, "%d->%d", begin, end); }else { sprintf(temp, "%d",end); } string s(temp); vs.push_back(s); return vs;}
0 0
- LeetCode228——Summary Ranges
- LeetCode228——Summary Ranges
- LeetCode228:Summary Ranges
- leetcode228. Summary Ranges
- leetcode228. Summary Ranges
- LeetCode——Summary Ranges
- Algorithms—228.Summary Ranges
- Algorithms—226.Summary Ranges
- Leetcode——228. Summary Ranges
- leetcode解题报告228——Summary Ranges
- leetcode刷题日记——Summary Ranges
- Summary Ranges
- summary ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- LeetCode Number of Islands
- GCD关于队列和函数对于调用线程的影响
- 我的 Xcode 插件单
- CodeForces 228E The Road to Berland is Paved With Good Intentions (2-Sat)
- 【2015_07_09】迷失
- LeetCode228——Summary Ranges
- dedecms(织梦)在后台新建新的模型时 ,点击编辑的时候 更新时间不能弹出
- Java字符参与运算和字符串参与运算
- 初次使用cocoapods注意事项
- LeetCode Bitwise AND of Numbers Range
- CDOJ 763 树上的鸟儿(水题/模拟题)
- LeetCode Happy Number
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) D. Restoring Numbers 构造 数学
- 学习STL过程中的一些零散记录4