![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
映射
shiyang6017
这个作者很懒,什么都没留下…
展开
-
Two sum
题意: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2015-11-17 17:10:43 · 267 阅读 · 0 评论 -
leetcode 41. First Missing Positive
class Solution { public:// 将nums[i] 放置到位置i上,然后从左到右依次遍历:找到第一个满足条件的i:位置i上的元素不是i,返回i int firstMissingPositive(vector& nums) { vector vec(nums.size() + 1, false); for (int i = 0; i < n原创 2016-08-06 22:13:56 · 152 阅读 · 0 评论 -
leetcode 168. Excel Sheet Column Title
class Solution { // 挺有意思的一题:从1到26映射,而不是0到25,这是问题的关键 public: string convertToTitle(int n) { string ret; while(n > 0){ int tmp = n % 26; ret += (tmp ? (tmp -原创 2016-09-09 17:14:04 · 156 阅读 · 0 评论 -
leetcode Substring with Concatenation of All Words
class Solution { // public: vector findSubstring(string s, vector& words) { for(const auto word : words) mp[word]++; int length = words[0].size(); for (int i =原创 2016-08-08 22:59:03 · 179 阅读 · 0 评论 -
146. LRU Cache
class LRUCache{ typedef list>::iterator Iter; public: LRUCache(int capacity) { cnt = capacity; } int get(int key) { // 时间复杂度O(1) auto iter = _map.find(key);原创 2016-09-05 20:33:19 · 236 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
题意: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3.原创 2015-11-19 13:01:00 · 266 阅读 · 0 评论 -
220. Contains Duplicate III
class Solution { // 木桶原理 public: bool containsNearbyAlmostDuplicate(vector& nums, int k, int t) { if ( k < 1 || t < 0 ) return false; const long long startPos = 0x8原创 2016-09-08 16:31:05 · 174 阅读 · 0 评论 -
leetcode 318. Maximum Product of Word Lengths
class Solution { // bitmap public: int maxProduct(vector& words) { vector bitmap(words.size(),0); for (int i = 0; i < words.size(); ++i) for (int j = 0; j < words[i原创 2016-09-08 17:00:42 · 196 阅读 · 0 评论