当前位置:网站首页>1640. Can you connect to form an array -c language implementation
1640. Can you connect to form an array -c language implementation
2022-07-27 09:22:00 【Mr Gao】
1640. Can you join to form an array -c Language implementation
Give you an array of integers arr , Every integer in the array Different from each other . There's another array of integers pieces, The integers are also Different from each other . Please use In any order Connect pieces In order to form arr . however , Don't allow For each array pieces[i] Reorder integers in .
If you can connect pieces The array in the form of arr , return true ; otherwise , return false .
Example 1:
Input :arr = [15,88], pieces = [[88],[15]]
Output :true
explain : Connect in turn [15] and [88]
Example 2:
Input :arr = [49,18,16], pieces = [[16,18,49]]
Output :false
explain : Even if the numbers match , You can't rearrange pieces[0]
Example 3:
Input :arr = [91,4,64,78], pieces = [[78],[4,64],[91]]
Output :true
explain : Connect in turn [91]、[4,64] and [78]
Personally, I think this question should have been very difficult ,leedcode in c There are few problems in language , The solution code is as follows , The code intensity is still very high :
bool canFormArray(int* arr, int arrSize, int** pieces, int piecesSize, int* piecesColSize){
int r[piecesSize];
int i;
for(i=0;i<piecesSize;i++){
r[i]=1;
}
for(i=0;i<arrSize;i++){
int rz=0;
for(int k=0;k<piecesSize;k++){
int j=i;
if(r[k]==1&&pieces[k][0]==arr[j]){
int p;
for( p=1;p<piecesColSize[k];p++){
if(pieces[k][p]!=arr[++j]){
break;
}
}
if(p==piecesColSize[k]){
r[k]=0;
i=j;
rz=1;
break;
}
}
}
if(rz==0){
return false;
}
}
return true;
}
边栏推荐
- 2068. 检查两个字符串是否几乎相等
- Huawei machine test question: Martian computing JS
- Nut joke based on arkui ETS
- MySQL transaction
- PVT's spatial reduction attention (SRA)
- IDL MODIS generate lookup table
- 存储和计算引擎
- [cloud native kubernetes practice] deploy the rainbow platform under the kubernetes cluster
- 二叉树遍历
- Hard core structure, violent interpretation
猜你喜欢

Explanation of common basic controls for C # form application (suitable for Mengxin)

Cross domain and processing cross domain

As a VC, the auction house invested Web3 for the first time

巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...

ArcGIS pro2.8 deep learning environment configuration based on rtx30 graphics card

JS call and apply

Music experience ceiling! Emotional design details of 14 Netease cloud music

ES6 new symbol data type
![[micro service ~sentinel] sentinel dashboard control panel](/img/df/2fbe7826ea2b80a81d29351052ae28.png)
[micro service ~sentinel] sentinel dashboard control panel
![[acl2020] a novel method of component syntax tree serialization](/img/24/b8ec489966f7b1deef82b2eefa4d1b.png)
[acl2020] a novel method of component syntax tree serialization
随机推荐
BGP联邦实验
[micro service ~sentinel] sentinel dashboard control panel
ctfshow 终极考核
IDL MODIS generate lookup table
The execution sequence of async/await, macro tasks and micro tasks
Data interaction based on restful pages
STL container - basic operation of queue and deque
Day 6 of learning C language
PVT's spatial reduction attention (SRA)
Principle of flex:1
Install Oracle under Linux, connect local pl/sql to Oracle import table under Linux, and create new user and password
D3.v3.js data visualization -- pictures and tips of force oriented diagram
[C language - zero foundation lesson 8] circular structure and break continue
如何注册码云账号
linux安装和远程连接mysql记录
存储和计算引擎
HBuilder 微信小程序中运行uni-app项目
基于ArkUI eTS开发的坚果食谱(NutRecipes
JS call and apply
[C language - zero foundation lesson 6] input and output sentence format and compound sentence