Eric liau

@ericliau

Joined on Feb 16, 2022

  • Permutation class Solution { public: void recur(vector<int> nums, vector<int> ans, vector<vector<int>>& res, int size){ if(!size){ res.push_back(ans); return; } for(int i = 0; i < size; i++){
     Like  Bookmark
  • permutation class Solution { public: vector<vector<int>> res; void recur(vector<int> nums, vector<int> ans, int size){ if(!size){ res.push_back(ans); return; } for(int i = 0; i < size; i++){
     Like  Bookmark
  • Use first for loop to find highest bar and its id. Then trace from left and right to this id individually. class Solution { public: int trap(vector<int>& height) { int max = -1, max_id, cur_hei = 0, res = 0, size = height.size(); for(int i = 0; i < size; i++){ if(height[i] > max){ max = height[i]; max_id = i;
     Like  Bookmark
  • recursive Use if(recnum > currec + 1) return false; to avoid unnecessary recursive. It return false if this star partition isn't the last star partition has be detected. It works because the remaining string s will only get shorter, and if the remaining part of string p can't match the remaining string s now, then it is even less likely to match a shorter string s. class Solution { public: int recnum = 0; bool check(string &s, string &p, int i, int j){ int s_size = s.size(), p_size = p.size(), currec = recnum; if(i == s_size && j == p_size) return true; if(i == s_size && p[j] == '*') return check(s, p, i, j + 1);
     Like  Bookmark