2026/2/14 21:20:59
网站建设
项目流程
网站建设空心正方形,自己注册一家公司需要多少钱,网站建设优秀网站建设,ui设计师需要考什么证书Problem: 846. Hand of Straights 一手顺子 解题过程 耗时97%#xff0c;首先判断数组长度是否被gS整除#xff0c;以及gS是否1#xff0c;然后排序的#xff0c;初始化状态数组status#xff0c;初始化变量#xff0c;pre初始化到hand[0]-1#xff0c;然后判断是否hand…Problem: 846. Hand of Straights 一手顺子解题过程耗时97%首先判断数组长度是否被gS整除以及gS是否1然后排序的初始化状态数组status初始化变量pre初始化到hand[0]-1然后判断是否hand[j] pre 1且status[j]false若前后数字相同则重置起始点start且j下一次从start开始若没有重置起始点也就是没有相同的数字则起始点j1然后pre hand[start] - 1若找遍了数组累计cnt!groupSize则返回falseCodeclass Solution { public: bool isNStraightHand(vectorint hand, int groupSize) { int n hand.size(); if(n % groupSize ! 0) return false; if(groupSize 1) return true; sort( hand.begin(), hand.end() ); int len n / groupSize, start 0, pre hand[0]-1, cnt, j; bool findstart; vectorbool status(n, false); for(int i 0; i len; i) { cnt 0; findstart false; for(j start; j n; j) { if(status[j]false hand[j] pre 1) { pre hand[j]; cnt; status[j] true; if(findstart false j1n hand[j]hand[j1]) { findstart true; start j1; j; } } if(cntgroupSize) break; } if(cnt ! groupSize) return false; if(findstart false) { start j 1; } if(start n) { pre hand[start] - 1; } } return true; } };