Skip to content

Instantly share code, notes, and snippets.

@Jimmy-Hu
Last active June 10, 2022 00:49
Show Gist options
  • Save Jimmy-Hu/e49aea298cc0f16286968b0e4a4f8d6b to your computer and use it in GitHub Desktop.
Save Jimmy-Hu/e49aea298cc0f16286968b0e4a4f8d6b to your computer and use it in GitHub Desktop.
Practice programmng

Jane Liao's Thesis

https://github.com/Jimmy-Hu/janeliao_thesis/compare/main...janeliao0105:main

Please notice that making sure the given git commit messages match the exact changes you modified.

In the commit 96f56405ddd8f466713339858d1f43670b251814, your commit message is Update gym_future. However, the things you actually done is adding files to dists folder.

Day 8: Dictionaries and Maps

https://www.hackerrank.com/challenges/30-dictionaries-and-maps/problem

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
 
int main() {
    string name;
    string number;
    map<string, string> phonebook;
    int n;
    cin >> n;
    while (n>0){
        cin >> name;
        cin >> number;
        phonebook.insert(pair<string,string>(name, number));
        n--; 
    }
    while ( cin>> name){
        if (phonebook.find(name) != phonebook.end()) {
                cout << name << "=" << phonebook.find(name)->second << endl;
        }
        else {
                cout <<"Not found"<< endl;
        }
    }
    return 0;
}

2sum (twoSum, May 13, 2022)

https://leetcode.com/problems/two-sum/submissions/

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target, int start = 0) {
        vector<vector<int>> res;
        unordered_set<int> s;
    
        for (int i = start; i < nums.size(); ++i) {
            if (res.empty() || res.back()[1] != nums[i]) {
                if (s.count(target - nums[i])) {
                    auto value = target - nums[i];
                    res.push_back({ static_cast<int>(find(nums.begin(), nums.end(), value) - nums.begin()), i });
                }
            }
            s.insert(nums[i]);
        }
                                             
        return res.at(0);
    }  
};

4sum (May 13, 2022)

https://leetcode.com/problems/4sum/

https://docs.google.com/document/d/1mcCitNotEGre0NUexFBndr2rLqz3cio3aFzNnHDGHeU/edit?hl=zh-TW

https://jamboard.google.com/d/1iZVxu3EwRyoz4VFFFO9EblC2rMTqJ60pJMcr5e9qHzk/viewer?hl=zh-TW&f=0

@Jimmy-Hu
Copy link
Author

Jimmy-Hu commented May 24, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment