Careercup - Microsoft面试题 - 4840369632051200
2014-05-10 07:06
原题:
Suppose you have a collection of collection
Eg : CEO-> Vps-> GMs ->..
CEO will contain collection of VP's, VP's will have collection of GM's and so on.
Suppose you need to find a particular GM is the alias is given. Write a linq query to get the employee details if the employee alias is given.
Hint : Use Recursion + Linq
题目:如果CEO手下有很多总监,总监手下有很多总经理,依此类推。那么通过一个名字和一个头衔,要如何找到符合条件的人?用递归和LINQ实现。
解法:这明显是C#问题吧。C#我勉强懂点基本语法,LINQ则完全不会,所以我只能用递归了。
代码:
// http://www.careercup.com/question?id=4840369632051200
// I believe this is not a typical interview question. You must've told them you know LINQ, before you're given this one.
// I've never learnt LINQ before, only basic knowledge of C# is not enough to solve this problem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace CSharp
{
class Person
{
public string title;
public string alias;
public List<Person> subordinate; public Person(string title, string alias)
{
this.title = title;
this.alias = alias;
subordinate = new List<Person>();
}
} class Solution
{
Person search(string title, string alias, Person source) {
if (source.title == title) {
return source.alias == alias ? source : null;
} Person result;
foreach(Person sub_source in source.subordinate)
{
result = search(title, alias, sub_source);
if (result != null)
{
return result;
}
} return null;
}
}
}
Careercup - Microsoft面试题 - 4840369632051200的更多相关文章
- Careercup - Microsoft面试题 - 6314866323226624
2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...
- Careercup - Microsoft面试题 - 6366101810184192
2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...
- Careercup - Microsoft面试题 - 24308662
2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...
- Careercup - Microsoft面试题 - 5700293077499904
2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...
- Careercup - Microsoft面试题 - 5204967652589568
2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...
- Careercup - Microsoft面试题 - 5175246478901248
2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...
- Careercup - Microsoft面试题 - 5718181884723200
2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...
- Careercup - Microsoft面试题 - 5173689888800768
2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...
- Careercup - Microsoft面试题 - 6282862240202752
2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...
随机推荐
- .NET中使用log4net
一,加载log4net引用 下载log4net.dll,我们这里使用的是.NET2.0 下载地址:http://files.cnblogs.com/gosky/log4net-1.2.13-bin-n ...
- ParameterDirection参数类型
IDataParameter[] paramArray = new IDataParameter[]{ AdoHelper.GetParameter("ReturnValue",D ...
- SQL Server编程(04)基本语法
一.定义变量 --简单赋值 declare @a int set @a=5 print @a --使用select语句赋值 declare @user1 nvarchar(50) select @ ...
- 集群session的一致性
一. 何为session 用户使用网站的服务,基本上需要浏览器和web服务器进行多次交互,web服务器如何知道哪些请求是来自哪个会话的? 具体方式为:在会话开始时,分配一个唯一的会话标识(sessio ...
- 基于zmap 的应用层扫描器 zgrab (一)
基于zmap 的应用层扫描器 zgrab (一) 介绍 zgrab 是基于zmap无状态扫描的应用层扫描器,可以自定义数据包,以及ip,domain之间的关联.可用于快速指纹识别爆破等场景. 安装 g ...
- 推荐个好东西swoole,php如虎添翼
Swoole:PHP语言的异步.并行.高性能网络通信框架,使用纯C语言编写,提供了PHP语言的异步多线程服务器,异步TCP/UDP网络客户端,异步MySQL,数据库连接池,AsyncTask,消息队列 ...
- PHP函数:生成N个不重复的随机数
思路:将生成的随机数存入数组,再在数组中去除重复的值,即可生成一定数量的不重复随机数. 程序: <?php /* * array unique_rand( int $min, int $max, ...
- 取消界面的title
在setContentView(R.layout.activity_main)方法上面添加代码(继承Activity的写法): requestWindowFeature(Window.FEATURE_ ...
- 用序列化工具写入xml
标本: <?xml version="1.0" encoding="UTF-8" standalone="true"?> //文 ...
- spark概论
一.概述 1.轻:(1)采用语言简洁的scala编写:(2)利用了hadoop和mesos的基础设施 2.快:spark的内存计算.数据本地性和传输优化.调度优化,使其在迭代机器学习,ad-hoc ...