正在阅读:

leetcode-1 – 两数之和

93

一. 目的

题目地址: https://leetcode-cn.com/problems/two-sum/

  1. 简单的暴力方法

class Solution {
    public:
        vector<int> twoSum(vector<int>& nums, int target) {
            vector<int> ret;
            int len=nums.size();
            int i, j;
            for (i = 0; i < len; ++i) {
                for (j = i + 1; j < len; ++j) {
                    if (nums[i] + nums[j] == target) {
                        ret.push_back(i);
                        ret.push_back(j);
                    } else
                        continue;
                }
            }
            return ret;
        }
};

留下脚印,证明你来过。

*

*

流汗坏笑撇嘴大兵流泪发呆抠鼻吓到偷笑得意呲牙亲亲疑问调皮可爱白眼难过愤怒惊讶鼓掌
关闭