* News/일상

August 18, 2021 daily

soicem 2021. 8. 18. 05:48

05:00 streching, jogging

05:45~06:50 leetcode

-Android Unlock Pattern: https://leetcode.com/explore/interview/card/google/62/recursion-4/484/

 

class Solution {
public:
    vector<vector<int>> directions = {{0, 1}, {1, 0}, {-1, 0}, {0, -1},
                                      {1, 1}, {1, -1}, {-1, 1}, {-1, -1},
                                      {1, 2}, {1, -2}, {2, 1}, {2, -1},
                                      {-1, 2}, {-1, -2}, {-2, 1}, {-2, -1}
                                     };
    
    int visited[3][3];
    
    int traverse(int y, int x, int m, int n, int d){
        int ret = 0;
        if(y < 0 || y > 2 || x < 0 || x > 2){
            return 0;
        }
        
        if(n < d){
            return 0;
        }
        
        if(visited[y][x] != 0){
            return 0;
        }
        visited[y][x] = 1;
        
        if(m <= d){
            ret += 1;
        }
        
        for(auto direction: directions){
            int yAxis = y + direction[0];
            int xAxis = x + direction[1];
            
            if(yAxis < 0 || yAxis > 2 || xAxis < 0 || xAxis > 2) continue;
            
            if(visited[yAxis][xAxis] != 0){
                ret += traverse(yAxis + direction[0], xAxis + direction[1], m, n, d + 1);
            } else {
                ret += traverse(yAxis, xAxis, m, n, d + 1);
            }
        }
        visited[y][x] = 0;
        return ret;
    }
    
    int numberOfPatterns(int m, int n) {
        int ans = 0;
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                ans += traverse(i, j, m, n, 1);
            }
        }
        return ans;
    }
};

마지막 케이스에서 타임아웃이라 개선 필요

 

17:00~18:00 weight training(chest)

'* News > 일상' 카테고리의 다른 글

공부 계획  (0) 2021.11.23
2022년 5월까지 목표  (0) 2021.09.21
2021년 개인 목표  (0) 2021.02.07
지금이 아니면  (0) 2021.01.30
효율적 생각  (0) 2020.06.12