<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      other 1878

      You are given an m x n integer matrix grid???.

      A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid???. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each rhombus sum:

      Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.

      Return the biggest three distinct rhombus sums in the grid in descending order. If there are less than three distinct values, return all of them.

       

      Example 1:

      Input: grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]
      Output: [228,216,211]
      Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.
      - Blue: 20 + 3 + 200 + 5 = 228
      - Red: 200 + 2 + 10 + 4 = 216
      - Green: 5 + 200 + 4 + 2 = 211
      

      Example 2:

      Input: grid = [[1,2,3],[4,5,6],[7,8,9]]
      Output: [20,9,8]
      Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.
      - Blue: 4 + 2 + 6 + 8 = 20
      - Red: 9 (area 0 rhombus in the bottom right corner)
      - Green: 8 (area 0 rhombus in the bottom middle)
      

      Example 3:

      Input: grid = [[7,7,7]]
      Output: [7]
      Explanation: All three possible rhombus sums are the same, so return [7].

      Constraints:

      • m == grid.length
      • n == grid[i].length
      • 1 <= m, n <= 50
      • 1 <= grid[i][j] <= 105
      class Solution {
          int m;
          int n;
          TreeSet<Integer> list = new TreeSet<>(); 
          public int[] getBiggestThree(int[][] grid) {
              m = grid.length;
              n = grid[0].length;
              // 計算半徑
              int len = Math.min(m, n) / 2;
              // for radius 0~len
              for(int radius = 0; radius <= len; radius++) {
                  // center start sx = radius  sy = radius
                  int sx = radius, sy = radius;
                  // center end ex = m - radius, ey = n - radius
                  int ex = m - radius, ey = n - radius;
                  // i in sx~ex
                  for(int i = sx; i <= ex; i++) {
                      for(int j = sy; j <= ey; j++) {
                          int sum = calculate(grid, i, j, radius);
                          if(sum >= 0) list.add(sum);
                      }
                  }
              }
              int size = Math.min(list.size(), 3);
              int[] result = new int[size];
              for(int i = 0; i < size; i++) {
                  result[i] = list.pollLast();
              }
              return result;
          }
      
          // 對以(x, y)為中心,radius為半徑的菱形求sum
          private int calculate(int[][] grid, int x, int y, int radius) {
              // 上下左右4個角
              int top = x - radius, bottom = x + radius, left = y - radius, right = y + radius;
              // 超出范圍校驗(yàn)
              if(top < 0 || bottom >= m || left < 0 || right >= n) return -1;
              // radius為0的直接返回
              if(radius == 0) return grid[x][y];
              
              int sum = 0;
              //對于4條邊分別進(jìn)行計算
              // left top
              for(int i = 0; i <= radius; i++) {
                  sum += grid[x - i][left + i];
              }
              // right top 
              for(int i = 0; i <= radius; i++) {
                  sum += grid[x - i][right - i];
              }
              // left bottom
              for(int i = 0; i <= radius; i++) {
                  sum += grid[x + i][left + i];
              }
              // right top 
              for(int i = 0; i <= radius; i++) {
                  sum += grid[x + i][right - i];
              }
              // 四個角多算了一次,要減去
              return sum - grid[x][left] - grid[x][right] - grid[top][y] - grid[bottom][y];
          }
      }

       

      posted @ 2024-11-25 01:24  xiaoyongyong  閱讀(43)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 久久99热只有频精品8| 中文字幕99国产精品| 欧美日韩v| 猫咪AV成人永久网站在线观看| 九九色这里只有精品国产| 成av人电影在线观看| 99久久久无码国产麻豆| av一区二区中文字幕| 亚洲熟妇国产熟妇肥婆| 日韩av一区二区高清不卡| 国产另类ts人妖一区二区| 国产超碰人人做人人爱ⅴa| 精品精品国产自在97香蕉| 99亚洲男女激情在线观看| 亚洲国产精品ⅴa在线观看| 视频一区二区三区自拍偷拍| 依依成人精品视频在线观看| 咸阳市| 亚洲日韩AV秘 无码一区二区| 无码人妻斩一区二区三区| 蒲江县| 综合色一色综合久久网| 精品一精品国产一级毛片| 国产精品免费中文字幕| 久久国产综合色免费观看| 亚洲国产欧美在线看片一国产| 熟女视频一区二区三区嫩草| 欧美乱妇高清无乱码免费| 国产v综合v亚洲欧美久久| 九九成人免费视频| 亚洲女人天堂| 丁香五月亚洲综合在线国内自拍| 精品久久精品久久精品久久| 九九热精品免费视频| 年日韩激情国产自偷亚洲| 十八禁午夜福利免费网站| 久久国产精品波多野结衣av| 美女一区二区三区亚洲麻豆| 偷偷做久久久久免费网站| 国产美女69视频免费观看| 国产成人啪精品视频免费网|