17 minute read

2020年 02 月 26 日更新

<-E> Two Sum 286ms 2.67%

vector<int> twoSum(vector<int>& nums, int target) {
    vector <int> answer;
    for (auto i = 0; i != nums.size(); i++) {
        for (auto j = i + 1; j != nums.size(); j++) {
            if (nums[i] + nums[j] == target) {
                answer.push_back(i);
                answer.push_back(j);
            }
        }
    }
    return answer;
}

大佬的解法: 利用hashmap的无序性。 hash.find(numberToFind) != hash.end() 如果没有找到,则将元素的值作为hash的key, 元素的位数为值添加到map中。以此类推直到找到该元素为止。

vector<int> twoSum(vector<int> &numbers, int target) {
    //Key is the number and value is its index in the vector.
    unordered_map<int, int> hash;
    vector<int> result;
    for (int i = 0; i < numbers.size(); i++) {
        int numberToFind = target - numbers[i];
        // if numberToFind is found in map, return them
        if (hash.find(numberToFind) != hash.end()) {
            result.push_back(hash[numberToFind]);
            result.push_back(i);
            return result;
        }
        // number was not found. Put it in the map.
        hash[numbers[i]] = i;
    }
    return result;
}

展开

使用unordered_map来做。 该数据结构被定义在unordered_map 库中。

  • unordered_map 内部实现为哈希表。(所以是无序的)
  • map 内部实现为红黑树(所以map内部的元素都是有序的)

map

优点:

  • 有序性
  • 内部由红黑树实现(使用红黑树特性的时候,效率快)

缺点:

  • 空间占用率高(节点)

unordered_map

优点:

  • 查找快

缺点:

  • 建立hash表的时候,消耗大量时间

<-M> Add Two Numbers 56ms 27.5%

(l1 ? l1->val : 0)
l1 = l1 ? l1->next : l1;
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        int remainder = 0;
        ListNode answer(0);
        ListNode *p = &answer;
        while (l1 || l2 || remainder) {
            int sum = (l1 ? l1->val : 0) + (l2 ? l2->val : 0) + remainder;
            remainder = sum / 10;
            p->next = new ListNode(sum % 10);
            p = p->next;
            l1 = l1 ? l1->next : l1;
            l2 = l2 ? l2->next : l2;
        }
        return answer.next;
    }
};

<-M> Longest Substring Without Repeating Characters

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int ans = 0;
        vector<-char> check;
        for (auto i = s.begin(); i != s.end(); i++) {
            for (auto j = i; j != s.end(); j++) {
                if (find(check.begin(), check.end(), *j) == check.end())
                    check.push_back(*j);
                else
                    break;
            }
            if (ans <- check.size()) {
                ans = check.size();
                check.clear();
            }
            else {
                check.clear();
            }
        }
        return ans;
    }
};

<-H> Median of Two Sorted Arrays 62ms

class Solution {
public:
    double findMedianSortedArrays(vector<-int>& nums1, vector<-int>& nums2) {
        vector<-int> Temp;
        for (int i = 0; i != nums1.size(); i++) {
            Temp.push_back(nums1[i]);
        }
        for (int i = 0; i != nums2.size(); i++) {
            Temp.push_back(nums2[i]);
        }
        sort(Temp.begin(), Temp.end());
        if (Temp.size() % 2 == 0)
            return (Temp[Temp.size() / 2 - 1] + Temp[Temp.size() / 2]) / 2.0;
        else
            return  Temp[Temp.size() / 2];
    }
};

<-M> Longest Palindromic Substring 9ms

class Solution {
public:
    string longestPalindrome(string s) {
    if (s.empty()) return "";
    if (s.size() == 1) return s;
    int min_start = 0, max_len = 1;
    for (int i = 0; i <- s.size();) {
        if (s.size() - i <-= max_len / 2) break;
        int j = i, k = i;
        while (k <- s.size()-1 && s[k+1] == s[k]) 
            ++k; 
      
        // Skip duplicate characters.
        
        i = k+1;
        while (k <- s.size()-1 && j > 0 && s[k + 1] == s[j - 1]) {
            ++k; --j; 
        } 
        
        // Expand.
        int new_len = k - j + 1;
        if (new_len > max_len) { 
            min_start = j; max_len = new_len; 
        }
    }
    return s.substr(min_start, max_len);
}
};

<-M> ZigZag Conversion 16ms

class Solution {
public:
    string convert(string s, int numRows) {
       if (numRows <-= 1 || s.size() <-= 1)
        return s;
        string result;
        for (int i = 0; i <- numRows; i++) {
            for (int j = 0, index = i; index <- s.size();j++, index = (2 * numRows - 2) * j + i) {
                result.append(1, s[index]);
                if (i == 0 || i == numRows - 1) 
                    continue;
                if (index + (numRows - i - 1) * 2 <- s.size())
                    result.append(1, s[index + (numRows - i - 1) * 2]);
            }
        }
        return result;
    }
};

<-E> Reverse Integer 15ms 77.99%

class Solution {
public:
    int reverse(int x) {
        int ans = 0;
        while (x) {
            int temp = ans * 10 + x % 10;
            if (temp / 10 != ans)
                return 0;
            ans = temp;
            x /= 10;
        }
        return ans;
    }
};

class Solution {
public:
   int reverse(int x){
        int n = 0;
        while(x != 0) {
            if(n > INT_MAX / 10 || n < INT_MIN / 10 || 
               (n == INT_MAX / 10 && x % 10 > INT_MAX % 10) ||
               (n == INT_MIN / 10 && x % 10 < INT_MIN % 10))
                return 0;
            n = 10 * n + x % 10;
            x /= 10;
        }
    return n;
    }
};

<-Bad Question -M> String to Integer (atoi)

class Solution {
public:
    int myAtoi(string str) {
        int ans = 0;
        int times = 1;
        int checkflag = 1;
        int end = 0;
        if (str[0] == '+') {
            end = 1;
        }
        if (str[0] == '-') {
            end = 1;
            checkflag = -1;
        }
        for (int i = str.size() - 1; i >= end; i--) {
            ans = (str[i] - '0') * times + ans;
            times *= 10;
        }
        return ans * checkflag;
    }
};

< -E> Palindrome Number

bool isPalindrome(int x) {
        if(x<0|| (x!=0 &&x%10==0)) return false;
        int sum=0;
        while(x>sum) {
            sum = sum*10+x%10;
            x = x/10;
        }
        return (x==sum)||(x==sum/10);
}

bool isPalindrome(int x){
    if(x < 0)
        return false;
    else {
        long int m = 0;
        int n = x;
        while(n != 0) {
            m = m * 10 + n % 10;
            n /= 10;
        }
        if(x == m)
            return true;
    }
    return false;
}

<-E> Palindrome Number

class Solution {
public:
    bool isPalindrome(int x) {
        if(x<0|| (x!=0 &&x%10==0)) return false;
        int sum=0;
        while(x>sum) {
            sum = sum*10+x%10;
            x = x/10;
        }
        return (x==sum)||(x==sum/10);

    }
};

<-E> Longest Common Prefix

求出最长的公共字串。这题有些歧义,根据Disucuss中的内容,增加条件如下:

{“a”,”a”,”b”} should give “” as there is nothing common in all the 3 strings. {“a”, “a”} should give “a” as a is longest common prefix in all the strings. {“abca”, “abc”} as abc {“ac”, “ac”, “a”, “a”} as a.

有了该条件后,可以使用双重循环进行求解,在一般的操作中,需要注重边界值的问题。

string longestCommonPrefix(vector<string>& strs) {
    string prefix = "";
    for(int idx=0; strs.size()>0; prefix+=strs[0][idx], idx++)
        for(int i=0; i<strs.size(); i++)
            if(idx >= strs[i].size() ||(i > 0 && strs[i][idx] != strs[i-1][idx]))
                return prefix;
    return prefix;
    }

<-E> Subtract the Product and Sum of Digits of an Integer

class Solution {
public:
    
    int subtractProductAndSum(int n) {
        int a = 1;
        int b = 0;
        int x;
        while (n != 0) {
            x = n % 10;
            a *= x;
            b += x;
            n = n / 10;
        }
        return a - b;
    }
    
};

<-E> Convert Integer to the Sum of Two No-Zero Integers

class Solution {
public:
    bool checkzero(int n) {
        int x;
        while (n != 0) {
            x = n % 10;
            if (x == 0)
                return false;
            n = n / 10;
        }
        return true;
    }
    vector<int> getNoZeroIntegers(int n) {
        vector<int> a;
        for (int i = 1; i != n; i++) {
            if (checkzero(n - i) && checkzero(i)) {
                a.push_back(i);
                a.push_back(n - i);
                return a;
            }
            
        }   
       
    }
};

<-E> Decompress Run-Length Encoded List

class Solution {
public:
    vector<int> decompressRLElist(vector<int>& nums) {
        vector<int> ans;
        for(int i = 0; i < nums.size(); i+=2) {
            for(int j = nums[i]; j != 0; j--) {
                ans.push_back(nums[i + 1]);
            }
        }
    return ans;    
    }
};

<-E> Decrypt String from Alphabet to Integer Mapping

class Solution {
public:
    string freqAlphabets(string s) {
        string a = "";
        int b;
        for(int i = s.size() - 1; i >= 0; i--) {
            if(s[i] != '#')
                b = s[i] - '0' + 96;
            else {
                b =   (s[i - 2] - '0' )* 10 +  (s[i - 1] - '0' ) + 96;
                i -= 2;
            }
            a = (char)b + a;
        }
        return a;
    }
};

<-E> Find N Unique Integers Sum up to Zero

class Solution {
public:
    vector<int> sumZero(int n) {
        vector<int> ans;
        if(n % 2) {
            ans.push_back(0);
            
        }
        else ;
        for(int i = 1; i <= n / 2; i++) {
            ans.push_back(i);
            ans.push_back(-i);
        }
        return ans;
    }
};

<-E> Replace Elements with Greatest Element on Right Side

class Solution {
public:
    vector<int> replaceElements(vector<int>& arr) {
        int temp = -1;
        arr.push_back(-1);
        for(int i = arr.size() - 2; i >= 0; i--) {
            if(arr[i] > temp)
                temp = arr[i];
            else
                arr[i] = temp;
        }
        arr.erase(arr.begin());
        return arr;
    }
};

<-E> Find Numbers with Even Number of Digits

class Solution {
public:
    bool checkEvenDights(int n) {
        int dights = 0;
        while(n != 0) {
            n /= 10;
            dights++;
        }
        if(dights % 2)
            return false;
        else
            return true;
    }
    int findNumbers(vector<int>& nums) {
        int ans = 0;
        for(auto i : nums) {
            if(checkEvenDights(i))
                ans++;
        }
        return ans;
    }
};

<-E> Convert Binary Number in a Linked List to Integer

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    int getDecimalValue(ListNode* head) {
        int ans = 0;
        while(head != NULL) {
            ans = ans * 2 + head->val;
            head = head->next;
        }
        return ans;
    }
};

<-E> Element Appearing More Than 25% In Sorted Array

class Solution {
public:
    
    int findSpecialInteger(vector<int>& arr) {
        int count = arr.size()  / 4;
        int temp = arr[0];
        int index = 0;
        for(int i = 1; i < arr.size(); i++) {
            index++;
            if(arr[i] != temp) {
                temp = arr[i];
                index = 0;
            }
            if(index >= count)
                return arr[i];
        }
        return arr[0];
    }
};

<-E> Jewels and Stones

// 1
class Solution {
public:
    int numJewelsInStones(string J, string S) {
        int ans = 0;
        for (auto i : S) {
            if (find(J.begin(), J.end(), i) != J.end())
                ans++;
        }
        return ans;
    }
};

// 2
class Solution {
public:
  int numJewelsInStones(string J, string S) {
        int check[128] = {0};
        for (int i = 0; i != S.size(); i++) {
            check[S[i]]++;
        }
        
        for (int i = 0; i != J.size(); i++) {
            check[J[i]] = -check[J[i]];
        }
        int ans = 0;
        for (int i = 0; i != 128; i++) {
            if (check[i] < 0)
                ans = ans - check[i];
        }
        return ans;
    }
};

<-E> Find Winner on a Tic Tac Toe Game

class Solution {
public:
    string tictactoe(vector<vector<int>>& moves) {
        vector<int> aRow(3);
        vector<int> bRow(3);
        vector<int> aCol(3);
        vector<int> bCol(3);
        int aIndex_1 = 0;
        int aIndex_2 = 0;
        int bIndex_1 = 0;
        int bIndex_2 = 0;
        for (int i = 0; i < moves.size(); i++) {
            int x = moves[i][0];
            int y = moves[i][1];   
            if (i % 2) {
                if (++aRow[x] == 3 || ++aCol[y] == 3 || (x == y && ++aIndex_1 == 3) || (x + y == 2 && ++aIndex_2 == 3))
                    return "B";
            }
            else {
                if (++bRow[x] == 3 || ++bCol[y] == 3 || (x == y && ++bIndex_1 == 3) || (x + y == 2 && ++bIndex_2 == 3))
                    return "A";
            }
        }     
        if (moves.size() == 9)
            return "Draw";
        else
            return "Pending";
    }
};

<-E> Minimum Time Visiting All Points

class Solution {
public:

        int minTimeToVisitAllPoints(vector<vector<int>>& points) {
            int ans = 0;
            for (int i = 1; i < points.size(); i++) {
                int x = points[i][0] - points[i - 1][0];
                int y = points[i][1] - points[i - 1][1];
                
                if(x < 0) x *= -1;
                if(y < 0) y *= -1;
                
                if(x == y) 
                    ans += x;
                else
                    ans += max(x,y);
            }
            return ans;
        }
};

<-E> Shift 2D Grid

// 1
class Solution {
public:
    vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {
       int row = grid.size();
        int col = grid[0].size();
        int n = row * col;
        vector<vector<int>> ans = grid;
        for(int i = 0; i < n; i++) {
            int j = (i + k) % n;
            int ri = i / col;
            int ci = i % col;
            int rj = j / col;
            int cj = j % col;
            ans[rj][cj] = grid[ri][ci];
        }
        return ans;
    }
};

// 2
class Solution {
public:
    vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {
       int row = grid.size();
        int col = grid[0].size();
        int n = row * col;
        vector<vector<int>> ans = grid;
        vector<int> tempArray;
        for(auto i : grid)
            for(auto j : i)
                tempArray.push_back(j);
        
        for(int i = 0; i != k; i++) {
            
            tempArray.insert(tempArray.begin(), tempArray[n - 1]);
            tempArray.pop_back();
        }
        
        int index = 0;
        for(int i = 0; i < row; i++) {
            for(int j = 0; j < col; j++) {
                ans[i][j] = tempArray[index];
                index++;
            }          
        }
        return ans;
    }
};

<-E> Check If It Is a Straight Line

class Solution {
public:
    bool checkStraightLine(vector<vector<int>>& coordinates) {
        bool temp = true;
        
        int a = coordinates[1][0] - coordinates[0][0];
        int b = coordinates[1][1] - coordinates[0][1];
        
        for(int i = 2; i < coordinates.size(); i++) {
            int x = coordinates[i][0] - coordinates[0][0];
            int y = coordinates[i][1] - coordinates[0][1];
            if(a * y != x * b) 
                return false;
        }            
       return true;
    }
};

<-E> Maximum 69 Number

class Solution {
public:
    
    int maximum69Number (int num) {
        int ans = 0;
        vector<int> temp;
        while(num != 0) {
            temp.push_back(num % 10);
             num /= 10;
        }
        
        for (int i = temp.size() - 1;  i >= 0; i--) {
            if (temp[i] == 6) {
                temp[i] = 9;
                break;
            }
        }
        for (int i = temp.size() - 1; i >= 0; i--) {
            ans = ans * 10 + temp[i];
        }
        
        return ans;
    }
};

// 2
class Solution {
public:

    int maximum69Number (int num) {
        string temp = to_string(num);
        for(int i = 0; i != temp.size(); i++)
            if(temp[i] == '6') {
                temp[i] = '9';
                break;
            }
        int ans = 0;
        for(int i = 0; i != temp.size(); i++)
            ans =  ans * 10  + (temp[i]  - '0');
        return ans;
    }
};

<-E> Cells with Odd Values in a Matrix

class Solution {
public:
    int oddCells(int n, int m, vector<vector<int>>& indices) {
        int rowValue, colValue;
        int a = 1;
        int b = 1;
        for(int i = 1; i != indices.size(); i++) {
            rowValue = colValue = 0;
            for(int j = i ; j >= 0; j--) {
                if(indices[i][0] == indices[j][0])
                    rowValue++;
                if(indices[i][1] == indices[j][1])
                    colValue++;
            }
            if(rowValue % 2)
                a++;
            else
                a--;
            if(colValue % 2)
                b++;
            else
                b--;
        }
        return a * m + b * n - 2 * a * b;
    }
};

<-E> Split a String in Balanced Strings

class Solution {
public:
    int balancedStringSplit(string s) {
        int index = 1;
        int ans = 0;
        char temp = s[0];
        for(int i = 1; i < s.size(); i++) {
            if(s[i] != temp) {
                index--;
            }
            else
                index++;
            if(index == 0) {
                ans++;
                temp = s[i + 1];
                index = 1;
                i++;
            }
        }
        return ans;
    }
};

<-E> Play with Chips

class Solution {
public:
    int minCostToMoveChips(vector<int>& chips) {
        int temp[2] = {0};
        for(int a : chips){
            temp[a%2]++;
        }
        return min(temp[0], temp[1]);
    }
};

<-E> Unique Number of Occurrences

class Solution {
public:
    bool uniqueOccurrences(vector<int>& arr) {
        int temp[2000] = {0};
        for(int i = 0; i < arr.size(); i++) {
            temp[arr[i] + 1000]++;
        }
        
        for(int i = 0; i < 2000; i++) {
            if(temp[i] != 0)
                for(int j = i + 1; j < 2000; j++) {
                    if(temp[j] != 0)
                        if(temp[i] == temp[j])
                            return false;
            }
        }
        return true;
    }
};

<-E> Minimum Absolute Difference

class Solution {
public:
    vector<vector<int>> minimumAbsDifference(vector<int>& arr) {
        sort(arr.begin(), arr.end());
        vector<vector<int>> ans;
        int temp = arr[1] - arr[0];
        for(int i = 1; i < arr.size(); i++) {
            int n = abs(arr[i] - arr[i - 1]);
            if(n < temp) {
                ans.clear();
                temp = n;
                ans.push_back({arr[i - 1], arr[i]});
            }
            else if(n == temp)
                ans.push_back({arr[i - 1], arr[i]});
                
        }
        return ans;
    }
};

<-E> Maximum Number of Balloons

class Solution {
public:       
    int maxNumberOfBalloons(string text) {
        int temp[5] = {0};
        
        for(int i = 0; i < text.size(); i++) {
            if(text[i] == 'a')
                temp[0]++;
            else if(text[i] == 'b')
                temp[1]++;
            else if(text[i] == 'l')
                temp[2]++;
            else if(text[i] == 'o')
                temp[3]++;
            else if(text[i] == 'n')
                temp[4]++;
        }
        temp[2] /= 2;
        temp[3] /= 2;

        int ans = temp[0];
        for(int i= 0; i < 5; i++ )
            if(ans > temp[i]) {
                ans = temp[i];
            }    
        return ans;
    }
};

<-E> Valid Parentheses

class Solution {
public:
    bool isValid(string s) {
        if (s.size() % 2)
            return false;
    
        stack<char> st;
        for (auto i = s.begin(); i != s.end(); i++) {
            if (s.empty() && (*i == ')' || *i == ']' || *i == '}')) {
                return false;
            }
            if (!st.empty() && (st.top() == '(' && (*i == ']' || *i == '}'))) {
                return false;
            }
            if (!st.empty() && (st.top() == '[' && (*i == ')' || *i == '}'))) {
                return false;
            }

            if (!st.empty() && (st.top() == '{' && (*i == ')' || *i == ']'))) {
                return false;
            }

            if (st.empty()) {
                st.push(*i);
                continue;
            }
            if ((st.top() == '(' && *i == ')') || (st.top() == '[' && *i == ']') || (st.top() == '{' && *i == '}')) {
                st.pop();
                continue;
            }
            st.push(*i);
        }

        return st.empty();
    }
};

<-E> Remove Duplicates from Sorted Array

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        if(nums.size() == 0) return 0;
        int index = 1;
        int check = nums[0];
        int set = 0;
        for(int i = 1; i != nums.size(); i++) {
            if(nums[i] != check) {
                check = nums[i];
                index++; 
                set ++;
                nums[set] = nums[i];
            }
            
            
        }
        return index;
    }
};

<-E> Lucky Numbers in a Matrix

class Solution {
public:
    vector<int> luckyNumbers (vector<vector<int>>& matrix) {
        vector<int> temp_min;
        vector<int> temp_max;
        vector<int> ans;
        
        for(int i = 0; i != matrix.size(); i++) {
            int check_min = matrix[i][0];
           for(int j = 0; j != matrix[0].size(); j++) {
              if(check_min > matrix[i][j])
                  check_min = matrix[i][j];
           }
            temp_min.push_back(check_min);
        }
        for(int i = 0; i != matrix[0].size(); i++) {
            int check_max = matrix[0][i];
           for(int j = 0; j != matrix.size(); j++) {
              if(check_max < matrix[j][i])
                  check_max = matrix[j][i];
           }
            temp_max.push_back(check_max);
        }
       
        for(int i = 0; i != temp_min.size(); i++) {
            if(find(temp_max.begin(), temp_max.end(), temp_min[i]) != temp_max.end())
                ans.push_back(temp_min[i]);
        }
        
        return ans;
    }
};

// 解法2
class Solution {
public:
    vector<int> luckyNumbers (vector<vector<int>>& matrix) {
        
        vector<int> ans;
        
        int liRow = -1;
        int liCol = -1;
        
        for( int i = 0; i < matrix.size(); ++i ) {
            int col = 0;
            for( int j = 1; j < matrix[i].size(); ++j ) {
                if ( matrix[i][j] < matrix[i][col])
                    col = j;
            }
            
            if ( liRow == -1 || matrix[liRow][liCol] < matrix[i][col]) {
                liRow = i;
                liCol = col;
            }
        }
        
        for( int i = 0; i < matrix.size(); ++i ) {
            if ( matrix[i][liCol] > matrix[liRow][liCol])
                return ans;
        }
        ans.push_back(matrix[liRow][liCol]);
        return  ans;
        
        
    }
};

<-E> Non-decreasing Array

class Solution {
public:
	bool checkPossibility(vector<int>& nums) {
		int cnt=0;
		for(int i=1;i<nums.size();i++){
			if(nums[i]<nums[i-1]){
				cnt++;
				if(i-2 >= 0 && nums[i-2]>nums[i]){
					nums[i]=nums[i-1];
				}
				if(cnt==2) break;
			}
		}
		return cnt<2;

	}
};

<-E> Defanging an IP Address

class Solution {
public:
    string defangIPaddr(string address) {
        string ans = "";
        
        for(auto i : address) 
            ans = ((i == '.') ? ans + "[.]": ans + i);
        return ans;
    }
    
};

<-E> Number of Steps to Reduce a Number to Zero

class Solution {
public:
    int numberOfSteps (int num) {
        int i = 0;
        while(num != 0) {
            if(num % 2) 
                num -= 1;
            else
                num /= 2;
            i++;
        }
        return i;
    }
};

<-E> How Many Numbers Are Smaller Than the Current Number

class Solution {
public:
    vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
        int bucket[101] = {0};
        for(auto i : nums)
            bucket[i]++;
        int index = 0;
        for(int i = 0; i != 101; i++) {
            if(bucket[i] != 0) {
                if(bucket[i] == 1) {
                    bucket[i] = index;
                    index++;
                }
                else {
                    int temp = bucket[i];
                    bucket[i] = index;
                    index += temp;
                }
            }
        }
        vector<int> ans(0, nums.size());
        for(auto i : nums) {
            ans.push_back(bucket[i]);
        }
        return ans;
    }
};

<-E> Create Target Array in the Given Order

class Solution {
public:
    vector<int> createTargetArray(vector<int>& nums, vector<int>& index) {
        vector<int> ans;
        for(int i = 0; i != nums.size(); i++) 
            ans.insert(ans.begin() + index[i], nums[i]);
        return ans;
    }
    
};

<-E> To Lower Case

class Solution {
public:
    string toLowerCase(string str) {
        for(auto &i: str) {
            if(i >= 'A' && i <= 'Z')
                i = i + 32;
        }
        return str;
    }
};

<-E> Increasing Decreasing String

class Solution {
public:
    string sortString(string s) {
        int temp_letters[26] = {0};
        for (auto i:s) {
            temp_letters[ i - 'a']++;
        }
        string ans = "";
        int i = 0;
        while(true) {
            if(ans.size() == s.size())
                break;
            i = 0;
        
            while(true) {
                if(temp_letters[i] > 0 ) {
                    ans += i + 'a';
                    temp_letters[i]--;
                }
                i++;
                if(i == 26)
                    break;;
            }
            i = 0;
            while(true) {
                if(temp_letters[25  - i] > 0 ) {
                    ans += 'z' - i;
                    temp_letters[25 - i]--;
                }
                i++;
                if(i == 26)
                    break;;
            }
        }
        return ans;
    }
};

<-E> Self Dividing Numbers

class Solution {
public:
    
    bool f(int n) {
        int temp = n;
        int digit;
         while(n != 0) {
            digit = n % 10;
            if(digit == 0 || temp % digit != 0 )
                return false;
            n /= 10;
        }
        return true;
    }
    
    
    vector<int> selfDividingNumbers(int left, int right) {
        vector<int> ans;
        for(int i = left; i <= right; i++) {
            if(i < 10)
                ans.push_back(i);
            else {
                if(f(i))
                    ans.push_back(i);
            }
        }
        return ans;
    }
};

<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>


<-E>