photo
Published on

100 days of C++

Authors
  • avatar
    Name
    Jashandeep Singh
    Twitter

This blog series is my ticket to explore C++ comprehensively. From the fundamental syntax to advanced concepts like templates, multithreading, and object-oriented programming, I'll navigate through the vast landscape of C++ together.

Each day holds a new challenge, a fresh concept to grasp, and an opportunity to strengthen my programming skills.

Day 1

Two_Sum_II_Input_Array_Is_Sorted
class Solution {
public:
    vector<int> twoSum(vector<int>& numbers, int target) {
        int i=0,j=numbers.size()-1;
        while(i<j){
            if(numbers[i]+numbers[j]==target) return {i+1,j+1};
            if(numbers[i]+numbers[j]<target){
                i++;
                while(i<j && numbers[i-1]==numbers[i]) i++;
            }
            else{
                j--;
                while(i<j && numbers[j+1]==numbers[j]) j--;
            }
        }
        return {-1,-1};
    }
};