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

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

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

      調(diào)和級數(shù) 3447

      Medium
       
      Topics
       
      Companies
       
      Hint

      You are given an integer array groups, where groups[i] represents the size of the ith group. You are also given an integer array elements.

      Your task is to assign one element to each group based on the following rules:

      • An element j can be assigned to a group i if groups[i] is divisible by elements[j].
      • If there are multiple elements that can be assigned, assign the element with the smallest index j.
      • If no element satisfies the condition for a group, assign -1 to that group.

      Return an integer array assigned, where assigned[i] is the index of the element chosen for group i, or -1 if no suitable element exists.

      Note: An element may be assigned to more than one group.

       

      Example 1:

      Input: groups = [8,4,3,2,4], elements = [4,2]

      Output: [0,0,-1,1,0]

      Explanation:

      • elements[0] = 4 is assigned to groups 0, 1, and 4.
      • elements[1] = 2 is assigned to group 3.
      • Group 2 cannot be assigned any element.

      Example 2:

      Input: groups = [2,3,5,7], elements = [5,3,3]

      Output: [-1,1,0,-1]

      Explanation:

      • elements[1] = 3 is assigned to group 1.
      • elements[0] = 5 is assigned to group 2.
      • Groups 0 and 3 cannot be assigned any element.

      Example 3:

      Input: groups = [10,21,30,41], elements = [2,1]

      Output: [0,1,0,1]

      Explanation:

      elements[0] = 2 is assigned to the groups with even values, and elements[1] = 1 is assigned to the groups with odd values.

      Constraints:

      • 1 <= groups.length <= 105
      • 1 <= elements.length <= 105
      • 1 <= groups[i] <= 105
      • 1 <= elements[i] <= 105
      class Solution {
          public int[] assignElements(int[] groups, int[] elements) {
              // 找到group中的最大值
              int max = 0;
              for(int ele : groups) {
                  max = Math.max(max, ele);
              }
              // 創(chuàng)建字典,遍歷elements,填入dict
              int[] dict = new int[max + 1];
              Arrays.fill(dict, -1);
              for(int i = 0; i < elements.length; i++) {
                  int num = elements[i];
                  // 如果超出了group最大值 直接不用考慮
                  // 如果已經(jīng)被標(biāo)記,說明它的約數(shù)已經(jīng)在它前面,比如[2,4] 到4的時候,其實2已經(jīng)標(biāo)記過了
                  if(num > max || dict[num] != -1) continue;
                  // 對num的倍數(shù)進行標(biāo)記
                  for(int j = num; j <= max; j = j + num) {
                      if(dict[j] != -1) continue;
                      dict[j] = i;
                  }
              }
              // 根據(jù)dict 對groups的數(shù)據(jù)填表,返回結(jié)果
              int[] result = new int[groups.length];
              for(int i = 0; i < groups.length; i++) {
                 result[i] = dict[groups[i]];
              }
              return result;
          }
      }

       

      posted @ 2025-02-16 08:15  xiaoyongyong  閱讀(12)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 久久精品国产精品亚洲毛片| 国产一区二区不卡在线看| 久久经精品久久精品免费观看| 欧美成人猛片aaaaaaa| 成人国产亚洲精品天堂av| 日韩中文字幕精品人妻| 推油少妇久久99久久99久久| 十八禁国产精品一区二区| 午夜国产精品福利一二| 日韩成人无码影院| 欧美人与动欧交视频| 二区三区亚洲精品国产| 亚洲成a人片在线观看日本| 午夜福利理论片高清在线| 国产一区二区在线激情往| 国产高潮视频在线观看| 婷婷久久香蕉五月综合加勒比 | 亚洲精品三区四区成人少| 国产一国产精品免费播放| 黑人异族巨大巨大巨粗| 偷拍精品一区二区三区| 亚洲最大成人在线播放| 乱色熟女综合一区二区三区| 亚洲一精品一区二区三区| 亚洲中文字幕一区二区| 国产专区一va亚洲v天堂| 国产欧美日韩精品第二区| 日韩福利片午夜免费观着| 欧美精品V欧洲精品| 国产四虎永久免费观看| 亚洲欧美日韩在线不卡| 久久人人97超碰人人澡爱香蕉| 中文字幕国产精品资源| 在线天堂中文新版www| 国产老熟女狂叫对白| 普宁市| 国产中年熟女高潮大集合| 中文字幕理伦午夜福利片| 日本肥老妇色xxxxx日本老妇| 亚洲综合一区二区三区不卡| 日韩精品中文字幕亚洲|