代码拉取完成,页面将自动刷新
https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba?tpId=265&tqId=39215&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D13&difficulty=undefined&judgeStatus=undefined&tags=&title=
class Solution {
public:
int minNumberInRotateArray(vector<int> rotateArray) {
int left = 0;
int right = rotateArray.size() - 1;
while(left < right){
int mid = (left + right) / 2;
//最小的数字在mid右边
if(rotateArray[mid] > rotateArray[right])
left = mid + 1;
//无法判断,一个一个试
else if(rotateArray[mid] == rotateArray[right])
right--;
//最小数字要么是mid要么在mid左边
else
right = mid;
}
return rotateArray[left];
}
};
https://www.nowcoder.com/practice/9023a0c988684a53960365b889ceaf5e?tpId=265&tqId=39212&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D13&difficulty=undefined&judgeStatus=undefined&tags=&title=
/*
struct TreeLinkNode {
int val;
struct TreeLinkNode *left;
struct TreeLinkNode *right;
struct TreeLinkNode *next;
TreeLinkNode(int x) :val(x), left(NULL), right(NULL), next(NULL) {
}
};
*/
class Solution {
public:
vector<TreeLinkNode*> nodes;
TreeLinkNode* GetNext(TreeLinkNode* pNode) {
if(pNode==nullptr)
{
return nullptr;
}
TreeLinkNode* root = pNode;
// 获取根节点
while(root->next) root = root->next;
InOrder(root);
for(int i=1; i<nodes.size(); ++i)
{
if(pNode==nodes[i-1])
{
return nodes[i];
}
}
return nullptr;
}
void InOrder(TreeLinkNode *root)
{
if(root==nullptr)
{
return;
}
InOrder(root->left);
nodes.push_back(root);
InOrder(root->right);
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。