leetcode推前力码接受的最喜欢/采访问题的提交

  1. 二和相关主题:数组、哈希表

class Solution {

public:

    vector twoSum(vector&; nums, int target) {

        unordered_map""> hash;

        for (int i = 0; i <; nums.size(); i++) {

            int j = nums[i];

            if (hash.find(j) != hash.end()) {

                return {hash[j], i};

            }

            hash[target - j] = i;

        }

        return vector();

    }

};

  1. 两个数相加相关主题:链表、数学、递归

/*

 * Definition for singly-linked list.

 * struct ListNode {

 *     int val;

 *     ListNode *next;

 *     ListNode() : val(0), next(nullptr) {}

 */