leetcode 2 sum c leetcode一天一道leetcode,先ac,再比较最优解法
- 两数之和
class Solution {
public:
vector twoSum(vector& nums, int target) {
vector out;
for(int i = 0; i < nums.size(); ++i) {
int m = target - nums[i];
for(int j = i + 1; j < nums.size(); ++j) {
if(nums[j] == m) {
out.push_back(i);
out.push_back(j);
break;
}
}
}
return out;
}
};
执行用时: 192 ms, 在Two Sum的C++提交中击败了10.58%的用户
- 两数相加(未ac)
class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
ListNode* l;
for(int i = 0; ; ++i) {
while...
暂无评论