赞
踩
解法:
class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int,int> james; for (int i = 0;i<nums.size();++i) { auto it = james.find(target-nums[i]); if (it != james.end()) { return { it ->second,i}; } james[nums[i]] = i ; } return { }; } };
解法:
class Solution { public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode* p = l1; // p作为l1的指针 ListNode* q = l2; int len_l1 = 1; int len_l2 = 1; //获取l1的长度 while(p->next != NULL) { ++ len_l1; p = p ->next; } //获取l2的长度 while(q->next != NULL) { ++ len_l2; q = q ->next; } //比较长度,补0. if (len_l1 <= len_l2) { for(int i = 0 ; i <len_l2-len_l1 ;i++) { p -> next = new ListNode(0); p = p->next; } } else { for(int i = 0 ; i
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。