Careercup - Google面试题 - 5661939564806144
2014-05-06 01:40
原题:
Give a N*N matrix, print it out diagonally.
Follow up, if it is a M*N matrix, how to print it out.
Example: print:
题目:按照题目示例给出的方式,输出一个矩阵。
解法:按题意写代码即可。
代码:
// http://www.careercup.com/question?id=5661939564806144
#include <cstdio>
#include <vector>
using namespace std; class Solution {
public:
void printDiagonal(vector<vector<int> > &matrix) {
int n, m; n = (int)matrix.size();
if (n == ) {
return;
}
m = (int)matrix[].size();
if (m == ) {
return;
} int i, j;
bool first; for (i = ; i < n + m; ++i) {
first = true;
for (j = (i < m ? i : m - ); j >= ; --j) {
if (i - j < || i - j > n - ) {
break;
}
printf((first ? "%d" : " %d"), matrix[i - j][j]);
first = false;
}
printf("\n");
}
};
};
Careercup - Google面试题 - 5661939564806144的更多相关文章
- Careercup - Google面试题 - 5732809947742208
2014-05-03 22:10 题目链接 原题: Given a dictionary, and a list of letters ( or consider as a string), find ...
- Careercup - Google面试题 - 5085331422445568
2014-05-08 23:45 题目链接 原题: How would you use Dijkstra's algorithm to solve travel salesman problem, w ...
- Careercup - Google面试题 - 4847954317803520
2014-05-08 21:33 题目链接 原题: largest number that an int variable can fit given a memory of certain size ...
- Careercup - Google面试题 - 6332750214725632
2014-05-06 10:18 题目链接 原题: Given a ,) (,) (,), (,) should be returned. Some suggest to use Interval T ...
- Careercup - Google面试题 - 5634470967246848
2014-05-06 07:11 题目链接 原题: Find a shortest path ,) to (N,N), assume is destination, use memorization ...
- Careercup - Google面试题 - 5680330589601792
2014-05-08 23:18 题目链接 原题: If you have data coming in rapid succession what is the best way of dealin ...
- Careercup - Google面试题 - 5424071030341632
2014-05-08 22:55 题目链接 原题: Given a list of strings. Produce a list of the longest common suffixes. If ...
- Careercup - Google面试题 - 5377673471721472
2014-05-08 22:42 题目链接 原题: How would you split a search query across multiple machines? 题目:如何把一个搜索que ...
- Careercup - Google面试题 - 6331648220069888
2014-05-08 22:27 题目链接 原题: What's the tracking algorithm of nearest location to some friends that are ...
随机推荐
- LLVM language 参考手册(译)(1)
LLVM Language Reference Manual 摘要 这个文档是一个LLVM汇编语言的参考手册.LLVM是一个基于Static Single Assignment(SSA - 静态单赋值 ...
- 2. XAML
1. 什么是 XAML XAML 可以说是 XML 的一个特殊子集,使用相同的语法,只是 XML 可以自定义任何的节点和属性,但 XAML 是有所限制的,只能在规定的命名空间下使用. 2. names ...
- ElasticSearch部署
安装jdk1.7 1.卸载Liunx自带的openjdk rpm -qa | grep jdk 查看当前的jdk版本 sudo yum -y remove java-1.7.0-openjdk-hea ...
- css 强制不换行
强制不换行 div{white-space:nowrap;} 自动换行 div{ word-wrap: break-word; word-break: normal; } 强制英文单词断行 div{w ...
- ThinkPHP实现联动菜单;
联动菜单,首先给你看看前端是怎么写的:
- Ajax的get请求向服务器请求数据五步骤?
如下: ①创建ajax对象 ②建立http请求 ③发送http请求 ④设置ajax对象状态改变的回调函数 ⑤判断ajax状态是否等于4,做相应的业务逻辑
- android 客户端支付宝 php服务器端编写
生成私钥 输入“genrsa -out rsa_private_key.pem 1024”命令,回车后,在当前 bin 文件目 录中会新增一个 rsa_private_key.pem 文件,其文件为原 ...
- Spark官方文档——独立集群模式(Standalone Mode)
除了部署在Mesos之上, Spark也支持独立部署模式,包括一个Spark master进程和多个 Spark worker进程.独立部署模式可以运行在单机上作为测试之用,也可以部署在集群上.如果你 ...
- R语言中判断是否是整数。以及读写excel
今天接手一个重复性工作, 需要手工把产品运营们在excel里写的活动规则, 插入数据库表中.为了减少出错, 提高效率. 再加上最近刚刚学R语言, 就用R练练手, 自动生成mysql的sql语句. 一次 ...
- 第二章 管理程序流(In .net4.5) 之 管理多线程
1. 概述 本章包括同步资源以及取消长时间任务相关的内容. 2. 主要内容 2.1 同步资源 ① lock关键字实现.会阻塞程序,有可能会导致死锁. ② volatile关键字可以禁用编译优化,用于避 ...