Git Product home page Git Product logo

algorithm's Introduction

📝 Algorithm

算法题练习记录博客,基于GitHub Action和GitHub Issue功能记录

🎯 Calendar

  • 2023/12
Mon Tue Wed Thu Fri Sat Sun
27 28 29 30 1 2 3
4 5 6 7 8 9 10🌟
11 12🌟 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

🍃 Records

# Title Tag Date
1 1. 两数之和 哈希表 2023-12-12T02:12:38Z
3 100. 相同的树 二叉树 递归 2023-12-10T12:14:09Z
2 110. 平衡二叉树 二叉树 搜索 2023-12-10T10:56:53Z

algorithm's People

Contributors

doragd avatar actions-user avatar

algorithm's Issues

1. 两数之和

1.两数之和
给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。
你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。
你可以按任意顺序返回答案。

使用哈希表unordered_map<int, int>

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 {};
    }
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.