leetcode刷题,总结,记录,备忘137
2015-06-23 00:08
267 查看
leetcode137
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
暂时没想出位操作的方法,,用的map容器,时间复杂度为O(n),,比较简单,,直接上代码,,我去搜搜别人的解法。。。
Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
暂时没想出位操作的方法,,用的map容器,时间复杂度为O(n),,比较简单,,直接上代码,,我去搜搜别人的解法。。。
class Solution { public: int singleNumber(vector<int>& nums) { map<int, int> mi; for (vector<int>::iterator it = nums.begin(); it != nums.end(); ++it) { mi[*it]++; } for (map<int, int>::iterator it = mi.begin(); it != mi.end(); ++it) { if (it->second < 3) return it->first; } } };
相关文章推荐
- 第一阶段站立会议6
- 毕胜自述:我是如何把奢侈品打到白菜价的 制造业的电子商务中国零售 小米启示录
- 梦断代码阅读笔记之一
- 实习生招聘笔试
- Codeforces #2B The least round way(DP)
- 在指定路径或者是文件名查找指定的字符串
- 《测试驱动开发》阅读笔记二
- servlet request 转发, 原文件和转发文件输出顺序
- 第一阶段站立会议5
- 08_Android中的SimpleAdapter的使用
- 08_Android中的SimpleAdapter的使用
- 最近需要看的博客
- 课程改进意见
- “数组最大值求和”结对情况
- 浅谈汇编器、编译器和解释器
- 让我们做个简单的解释器(三)
- 让我们做个简单的解释器(一)
- 用 350 行代码从零开始,将 Lisp 编译成 JavaScript
- 更好利用 tmux 会话的 4 个技巧
- Python中线程编程之threading模块的使用详解