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的更多相关文章

  1. Careercup - Microsoft面试题 - 6314866323226624

    2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...

  2. Careercup - Microsoft面试题 - 6366101810184192

    2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...

  3. Careercup - Microsoft面试题 - 24308662

    2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...

  4. Careercup - Microsoft面试题 - 5700293077499904

    2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...

  5. Careercup - Microsoft面试题 - 5204967652589568

    2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...

  6. Careercup - Microsoft面试题 - 5175246478901248

    2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...

  7. Careercup - Microsoft面试题 - 5718181884723200

    2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...

  8. Careercup - Microsoft面试题 - 5173689888800768

    2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...

  9. Careercup - Microsoft面试题 - 6282862240202752

    2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...

随机推荐

  1. iOS键盘类型

    一.键盘风格 UIKit框架支持8种风格键盘. typedef enum { UIKeyboardTypeDefault,                // 默认键盘:支持所有字符 UIKeyboa ...

  2. 移植u-boot-1.1.6之mtdparts分区

    和u-boot高版本不同,mtdparts命令没有cmd_mtdparts这么一个单独的文件来实现. 不过,搜索uboot可以在cmd_jffs2.c里面看到如下代码: U_BOOT_CMD( mtd ...

  3. MHA学习笔记

    MHA是一款开源的MySQL高可用程序,为MySQL主从复制架构提供了节点故障转移功能,当 master发生故障时MHA会自动提升拥有最新数据的slave节点成为新的主节点,还提供了master节 点 ...

  4. php验证是否是md5编码的代码

    php验证是否是md5编码的示例. 代码很简单,使用了正则表达式. function is_md5($password) {     return preg_match("/^[a-z0-9 ...

  5. 详解 CSS 属性 - :before && :after

    现在我们经常在 html 源码中看到如下的写法: 这里的 ::after 和 ::before 就是我们今天来探讨的 css 伪元素之二 - :before && :after. 伪元 ...

  6. pure css兼容IE

    <!--[if lte IE 8]> <link rel="stylesheet" href="pure/0.5.0/grids-responsive- ...

  7. JTable的DefaultModel方法getValueAt(a,row)

    行和列都是从0开始索引的,而且不包括netbeans生成的表格头,而是从数据开始,否则就会报错

  8. printf输出格式总结

    printf函数称为格式输出函数,其关键字最末一个字母f即为"格式"(format)之意.其功能是按用户指定的格式,把指定的数据显示到显示器屏幕上. printf函数调用的一般形式 ...

  9. 误删system04.dbf 报:ORA-01157 ORA-01110

    DB:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production OS:Oracle Linux 5.7 ...

  10. Node.js中的模块化

    每天一篇文章来记录记录自己的成长吧.大二,该静心了.加油~ 好了,废话不多说,今天说说nodejs中的模块化.(注:此文为自己对书nodejs实战的总结) nodejs一个重要的特性就是模块化,模块就 ...