logseq_notes/journals/2023_04_21.md
2023-06-14 14:27:22 +08:00

2.6 KiB

  • 中国地下乐队 collapsed:: true
    • 退格 backspace (psychedelic rock
    • 兵马司(发行)
    • Re tros (daft funk
    • Dream can
  • Leetcode - Rotate Image id:: 64422d1f-5db3-435d-ab4e-2b9fe5fd47cd collapsed:: true
    • Times:
      • Time when completed: 14:28
      • Time taken to complete: 15 mins ( with solution in mind )
      • DONE Revisions: SCHEDULED: <2023-05-26 Fri> :LOGBOOK:
        • State "DONE" from "LATER" [2023-04-28 Fri 16:45]
        • State "DONE" from "LATER" [2023-05-23 Tue 20:26] :END:

    • Tags:
      • Algorithms: #math
      • Data structures: #array
      • Difficulty: #difficulty_easy
      • Platforms: #leetcode
    • Links:
    • Problem:
      • You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).
      • You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
    • Examples:
    • Constraints:
      • n == matrix.length == matrix[i].length
      • 1 <= n <= 20
      • -1000 <= matrix[i][j] <= 1000
    • Thoughts:
      • Intuition:
        • The solution is tricky, which requires you to use math.
        • In order to do this, first, transpose, then reflect the matrix.
    • Solution:
      • java
        • class Solution {
            private void swap(int[][] matrix, int a, int b, int x, int y) {
              int temp = matrix[a][b];
              matrix[a][b] = matrix[x][y];
              matrix[x][y] = temp;
            }
            public void rotate(int[][] matrix) {
              // transpose and reflect
              for (int i = 0; i < matrix.length; i++) {
                for (int j = 0; j < i; j++) {
                  swap(matrix, i, j, j, i);
                }
              }
          
              for (int i = 0; i < matrix.length; i++) {
                for (int j = 0; j < matrix.length / 2; j++) {
                  swap(matrix, i, j, i, matrix.length - j - 1);
                }
              }
            }
          }
          
  • DONE 购物清单 Shopping lists
    • DONE 香熏/香氛
    • DONE 耳塞
  • DONE 查英语成绩 SCHEDULED: <2023-04-25 Tue>
  • DONE 报名 SCHEDULED: <2023-05-08 Mon>
  • DONE 写乐理练习的作业