├── 1. Two_Sum.cpp ├── 20. Valid_Parenthesis.cpp ├── LICENSE └── README.md /1. Two_Sum.cpp: -------------------------------------------------------------------------------- 1 | // Intuition: 2 | // The code utilizes a brute force approach to solve the problem. It iterates through each element of the vector and checks all possible pairs of elements to find the desired sum. 3 | 4 | // Approach: 5 | // Initialize n as the size of the vector, which represents the number of elements. 6 | // Start iterating through each element of the vector using the variable i as the index. 7 | // For each element at index i, iterate through the remaining elements in the vector using the variable j as the index, starting from i+1. 8 | // Check if the sum of nums[i] and nums[j] equals the target value. 9 | // If it does, return a vector containing the indices {i, j} as the result. 10 | // If no pair is found that satisfies the condition, return an empty vector as the result. 11 | 12 | // Complexity Analysis: 13 | // Time Complexity: The code uses nested loops to iterate through the vector, resulting in a time complexity of O(n^2), 14 | // where n is the number of elements in the vector. 15 | // Space Complexity: The space complexity is O(1) since the code only uses a constant amount of extra space to store the indices or an empty vector. 16 | // It's worth noting that this brute force approach is not the most efficient solution for the problem. 17 | // If the input vector is very large, the time complexity of O(n^2) can be quite costly. There are more optimized algorithms, like using a hash table or sorting the vector, 18 | // which can solve the problem in a more efficient manner. 19 | 20 | 21 | 22 | class Solution { 23 | public: 24 | vector twoSum(vector& nums, int target) { 25 | int n=nums.size(); 26 | for(int i=0; i