剑桥offer(21~30)
21.题目描述
22.题目描述
class Solution {
public:
    int MoreThanHalfNum_Solution(vector<int> numbers) {
         map<int,int> m;
        map<int,int>::iterator it;
            for(int i=;i<numbers.size();i++)
                m[numbers[i]]++;
            for(it=m.begin();it!=m.end();it++)
            {
                if(it->second>numbers.size()/)
                return it->first;
            }
        return ;
    }
};
23.题目描述
class Solution {
public:
    vector<int> GetLeastNumbers_Solution(vector<int> input, int k) {
        vector<int>r;
        if(input.empty()||k>input.size()) return r;
        sort(input.begin(),input.end());
        r.assign(input.begin(),input.begin()+k);
        return r;
    }
};
24.题目描述
class Solution {
public:
    int FindGreatestSumOfSubArray(vector<int> array) {
        if(array.size() == )return ;
        int sum = array[];
        int tmp = array[];
        for (int i=;i<array.size();i++){
            tmp = (tmp>)?tmp+array[i]:array[i];
            sum = tmp>sum?tmp:sum;
        }
        return sum;
    }
};
25.题目描述
class Solution {
public:
    int NumberOf1Between1AndN_Solution(int n)
    {
     int count = ;
        for(int i=; i<=n; i++){
            int temp = i;
            //如果temp的任意位为1则count++
            while(temp){
                if(temp% == ){
                    count++;
                }
                temp /= ;
            }
        }
        return count;
    }
};
26.题目描述
class Solution {
public:
  static bool cmp(int a,int b){
         string A="";
         string B="";
         A+=to_string(a);
         A+=to_string(b);
         B+=to_string(b);
         B+=to_string(a);
         return A<B;
     }
     string PrintMinNumber(vector<int> numbers) {
         string  answer="";
         sort(numbers.begin(),numbers.end(),cmp);
         for(int i=;i<numbers.size();i++){
             answer+=to_string(numbers[i]);
         }
         return answer;
     }
};
27.题目描述
class Solution {
public:
    int GetUglyNumber_Solution(int index) {
    if (index <= )return ;
    if (index == ){
        return ;
    }
    int m2=,m3=,m5=;
     vector<int>a(index);
        a[]=;
    for(int i=;i<index;i++){
        a[i]=min(a[m2]*,min(a[m3]*,a[m5]*));
        if(a[i]==a[m2]*)m2++;
        if(a[i]==a[m3]*)m3++;
        if(a[i]==a[m5]*)m5++;
    }
        return a[index-];
    }
};
28.题目描述
class Solution {
public:
    int FirstNotRepeatingChar(string str) {
        char s[] = {};
        int i=;
        while(str[i]!='\0'){
            s[str[i]]++;
            i++;
        }
         i=;
        while(str[i]!='\0'){
            if(==s[str[i]]){
                return i;
            }
            i++;
        }
        return -;
    }
};
29.题目描述
30.题目描述
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* FindFirstCommonNode( ListNode *pHead1, ListNode *pHead2) { if (!pHead1 || !pHead2) return NULL; stack<ListNode *>p1;
stack<ListNode *>p2;
ListNode* node = NULL; while (pHead1){
p1.push(pHead1);
pHead1 = pHead1->next;
}
while (pHead2){
p2.push(pHead2);
pHead2 = pHead2->next;
}
while ((p1.size()> && p2.size()>) && p1.top() == p2.top()){ node = p1.top();
p1.pop();
p2.pop(); }
return node;
} };
剑桥offer(21~30)的更多相关文章
- 2017年1月4日 星期三 --出埃及记 Exodus 21:30
		2017年1月4日 星期三 --出埃及记 Exodus 21:30 However, if payment is demanded of him, he may redeem his life by ... 
- 2018-10-13 21:30:51 conversion of number systems
		2018-10-13 21:30:51 c language 二进制.八进制和十六进制: 1) 整数部分 十进制整数转换为 N 进制整数采用“除 N 取余,逆序排列”法. 十进制数字 36926 转 ... 
- 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
		剑指 Offer 21. 调整数组顺序使奇数位于偶数前面 Offer 21 这题的解法其实是考察快慢指针和头尾指针. package com.walegarrett.offer; /** * @Aut ... 
- 【剑指Offer】俯视50题之21 - 30题
		面试题21包括min函数的栈 面试题22栈的压入.弹出序列 面试题23从上往下打印二叉树 面试题24二叉搜索树的后序遍历序列 面试题25二叉树中和为某一值的路径 面试题26复杂链表的复制 ... 
- 在线体验 Windows 11「GitHub 热点速览 v.21.30」
		作者:HelloGitHub-小鱼干 有什么比无需安装系统,检测硬件兼容度,只要打开一个浏览器,输入某个神秘的地址回车,即可体验 Windows 11 更棒的呢?windows11 就是这么一个小工具 ... 
- 【Java】 剑指offer(21) 调整数组顺序使奇数位于偶数前面
		本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集 题目 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇 ... 
- 剑桥offer(31~40)
		31.题目描述 统计一个数字在排序数组中出现的次数. 思路:找到最低和最高,相减 class Solution { public: int GetNumberOfK(vector<int> ... 
- 剑桥offer系列(1~10)
		1.题目描述 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 思路:从左下开始, ... 
- 剑指offer 面试30题
		面试30题: 题目:包含min函数的栈 题:定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数.在该栈中,调用min.push.pop的时间复杂度都是O(1) 解题思路:1)如果每次 ... 
随机推荐
- tomcat部署项目,80端口被占,解决方案
			第一个解决方案: 最大的可能:被System占了. 解决Windows Server 2008 System进程占用80端口 输入netstat -ano 可以看到80端口被PID4占用,于是打开任务 ... 
- 前端开发工程师 - 03.DOM编程艺术 - 第1章.基础篇(下)
			第1章.基础篇(下) Abstract: 数据通信.数据存储.动画.音频与视频.canvas.BOM.表单操作.列表操作 数据通信(HTTP协议) HTTP事务: 客户端向服务器端发送HTTP请求报文 ... 
- 小程序button 去边框
			/*使用 button::after{ border: none; } 来去除边框*/.free-btn-bordernone{ background: none !important; color: ... 
- lintcode: Missing String
			Missing String 描述: Given two strings, you have to find the missing string. Have you met this questi ... 
- jQuery 对象 与 原生 DOM 对象 相互转换
			区别 jQuery 选择器得到的 jQuery对象 和 原生JS 中的document.getElementById() document.querySelector取得的 DOM对象 是两种不同类型 ... 
- 4-1:实现tee命令
			#include <stdio.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h& ... 
- c语言乐曲演奏——《千本樱》
			这个程序着实花费了我好长的时间,我本身对音乐一窍不通,先是跟着girl friend学习了简谱,根据c调44拍的<千本樱>写下了下面的程序. #include<stdio.h> ... 
- 接口文档管理工具-Postman、Swagger、RAP(转载)
			接口文档管理工具-Postman.Swagger.RAP 转自:http://www.51testing.com/html/10/n-3715910.html 在项目开发测试中,接口文档是贯穿始终的. ... 
- 寒假学习计划——MOOC
			课程 西安交通大学[https://www.icourse163.org/course/XJTU-46006?tid=1002265006] 理由 本身中国大学mooc里c++课程不多,完结了能够有很 ... 
- java设计模式简介
			设计模式简介: 设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用.设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案.这些解决方案是众多 ... 
