# Two-Pointer

## `Q1:` [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer/)

```cpp
class Solution {
public: 

    int pivotInteger(int n) {

        int leftSum = 0;
        int rightSum = 0;
        
        int s = 1;
        int e = n;

        while(s <= e) {
            if(leftSum + s < rightSum) leftSum += s++;
            else rightSum += e--;
        }

        if(leftSum + s == rightSum) return s;
        if(leftSum == rightSum + e) return e;
        
        return -1;
    }
};
```
