Careercup - Facebook面试题 - 4713484755402752
2014-05-02 00:30
原题:
Given two arrays of sorted integers, merge them keeping in mind that there might be common elements in the arrays and that common elements must only appear once in the merged array.
题目:归并两个已排序的数组,重复元素只能在归并的结果里出现一次。
解法:题意很清晰,只是没有说两个数组里本身是否有重复元素,依题意写代码就可以了。
代码:
// http://www.careercup.com/question?id=4713484755402752
#include <vector>
using namespace std; class Solution {
public:
void mergeSortedArray(vector<int> &a, vector<int> &b, vector<int> &c) {
int na, nb; na = (int)a.size();
nb = (int)b.size();
if (na == ) {
c = b;
return;
} else if (nb == ) {
c = a;
return;
} int i, j;
i = j = ;
while (i < na && j < nb) {
if (a[i] < b[j])
c.push_back(a[i++]);
} else if (a[i] > b[j]) {
c.push_back(b[j++]);
} else {
c.push_back((a[i++], b[j++]));
}
}
while (i < na) {
c.push_back(a[i++]);
}
while (j < nb) {
c.push_back(b[j++]);
}
}
};
Careercup - Facebook面试题 - 4713484755402752的更多相关文章
- Careercup - Facebook面试题 - 6026101998485504
2014-05-02 10:47 题目链接 原题: Given an unordered array of positive integers, create an algorithm that ma ...
- Careercup - Facebook面试题 - 5344154741637120
2014-05-02 10:40 题目链接 原题: Sink Zero in Binary Tree. Swap zero value of a node with non-zero value of ...
- Careercup - Facebook面试题 - 5765850736885760
2014-05-02 10:07 题目链接 原题: Mapping ' = 'A','B','C' ' = 'D','E','F' ... ' = input: output :ouput = [AA ...
- Careercup - Facebook面试题 - 5733320654585856
2014-05-02 09:59 题目链接 原题: Group Anagrams input = ["star, astr, car, rac, st"] output = [[& ...
- Careercup - Facebook面试题 - 4892713614835712
2014-05-02 09:54 题目链接 原题: You have two numbers decomposed in binary representation, write a function ...
- Careercup - Facebook面试题 - 6321181669982208
2014-05-02 09:40 题目链接 原题: Given a number N, write a program that returns all possible combinations o ...
- Careercup - Facebook面试题 - 5177378863054848
2014-05-02 08:29 题目链接 原题: Write a function for retrieving the total number of substring palindromes. ...
- Careercup - Facebook面试题 - 4907555595747328
2014-05-02 07:49 题目链接 原题: Given a set of n points (coordinate in 2d plane) within a rectangular spac ...
- Careercup - Facebook面试题 - 5435439490007040
2014-05-02 07:37 题目链接 原题: // merge sorted arrays 'a' and 'b', each with 'length' elements, // in-pla ...
随机推荐
- 每天一道LeetCode--371. Sum of Two Integers
alculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Examp ...
- DWZ (JUI) 教程 DWZ中dialog层的刷新
在DWZ开发过程中经常会遇到的一种情况就是:在navTab页面中通过a标签打开一个dialog,在dialog层进行操作后,需要对该dialog层进行必要的刷新操作. 1.首先讲一下思路: 在非dia ...
- 最新32位和64位xp,win7,win8,win10系统大全(电脑装机版)
一.系统主要特点 1.安装维护方便快速 - 全自动无人值守安装,采用万能GHOST技术,安装系统过程只需3-5分钟,适 合新旧各种机型. - 集成常见硬件驱动,智能识别+预解压技术,绝大多数硬件可以快 ...
- Windows 10 (or 8)Chrome 观看视频发生flash不能加载,即"could't load plugins"原因之一
最近一直如题,不能看视频,后来发现从一个已经使用管理员权限打开的应用转到Chrome就可以加载flash,而从桌面打开Chrome就加载不了. 今天再次查找信息,从Ubuntu下Chrome不能加载f ...
- 30类css选择器
大概大家都知道id,class以及descendant选择器,并且整体都在使用它们,那么你正在错误拥有更大级别的灵活性的选择方式.这篇文章里面提到的大部分选择器都是在CSS3标准下的,所以它们只能在相 ...
- 支持向量机 support vector machine
SVM(support Vector machine) (1) SVM(Support Vector Machine)是从瓦普尼克(Vapnik)的统计学习理论发展而来的,主要针对小样本数据进行学习. ...
- opencv 手写选择题阅卷 (二)字符识别
opencv 手写选择题阅卷 (二)字符识别 选择题基本上只需要识别ABCD和空五个内容,理论上应该识别率比较高的,识别代码参考了网上搜索的代码,因为参考的网址比较多,现在也弄不清是参考何处的代码了, ...
- Debug Intro
The ABAP Debugger is used tool to execute and analyze programs line by line. Using it we can check t ...
- ADO.NET笔记——基本概念
ADO.NET中的主要对象: Connection:连接对象.用于建立从应用程序到数据库服务器指定数据库的连接通道 Command:命令对象.用于执行增删查改等数据库语句命令 DataReader:数 ...
- Android Studio添加jar包
1.先把jar包复制到项目的lib下,