![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
楠倏之语
这个作者很懒,什么都没留下…
展开
-
Two Sum
class Solution {public: vector twoSum(vector& nums, int target) { vector out; map nummap; for(int i=0;i if(!nummap.count(nums[i]))nummap.insert(pair(nu原创 2015-09-26 00:15:06 · 382 阅读 · 0 评论 -
Add Two Numbers
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2015-09-27 11:08:39 · 369 阅读 · 0 评论 -
Remove Nth Node From End of List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* removeNthFromEnd(ListNode*原创 2015-09-28 09:42:29 · 376 阅读 · 0 评论 -
Add Binary
class Solution {public: string addBinary(string a, string b) { int length1 = a.size(); int length2 = b.size(); int add = 0; string out; int i = 0;原创 2015-09-27 15:49:01 · 392 阅读 · 0 评论 -
Number of 1 Bits
解法来源剑指offer,题101.可能引起死循环的解法int NumberOf1(int n){int count = 0;while(n){if(n&1)count++;n = n >> 1;}return count;}若为负数如0x80000000移位为0xC0000000,最终变为0xFFFFFFFF陷入死循环。2.better原创 2015-09-26 10:54:58 · 273 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
class Solution {public: int lengthOfLongestSubstring(string s) { int count=0; int max=0; int k=0; vector temp; for(int i=0;i<s.size();i++){ for(int j=k;j<temp.size();j++){ if(s[i]==temp[j]){ k = j + 1原创 2015-09-27 22:35:39 · 323 阅读 · 0 评论 -
Pow(x,n)
class Solution {public: double myPow(double x, int n) { double result = 0; if(n == 0) return 1.0; else if(n result = 1.0/power(x, -n);原创 2015-10-09 11:00:21 · 346 阅读 · 0 评论