Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #define endl '\n'
- #define ll long long // range : -9*10^18 ~ 9*10^18
- class Solution {
- public:
- vector<int> twoSum(vector<int>& nums, int target) {
- unordered_set<int> s;
- vector<int> ans;
- for(auto e : nums){
- cout << e << endl;
- }
- for(int i=0; i<nums.size(); i++){
- auto search = s.find(nums[i]);
- if(search != s.end()){
- ans.push_back(nums[i]);
- ans.push_back(*search);
- break;
- }else{
- s.insert(nums[i]);
- }
- }
- for(auto e : s){
- cout << e << endl;
- }
- return ans;
- }
- void prac(){
- cout << "hello world" << endl;
- }
- };
- int main(){
- IOS;
- Solution sol = Solution();
- vector<int> input {2, 7, 11, 15};
- int target = 9;
- vector<int> ans = sol.twoSum(input, target);
- cout << ans[0] << ' ' << ans[1];
- // sol.prac();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement