zoukankan      html  css  js  c++  java
  • 30 Day Challenge Day 10 | Leetcode 1. Two Sum

    题解

    方法:哈希表

    class Solution {
    public:
        vector<int> twoSum(vector<int>& nums, int target) {
            unordered_map<int, int> hash;
            for(int i = 0; i < nums.size(); i++) {
                if(hash.count(target-nums[i])) {
                    return {hash[target-nums[i]], i};
                }
                hash[nums[i]] = i;
            }
            return {};
        }
    };
    
  • 相关阅读:
    spoj705
    bzoj2440
    spoj220
    bzoj2301
    hdu1695
    poj3294
    hdu3518
    poj3693
    函数
    样式
  • 原文地址:https://www.cnblogs.com/casperwin/p/13688989.html
Copyright © 2011-2022 走看看