Careercup - Microsoft面试题 - 4840369632051200
2014-05-10 07:15
274 查看
2014-05-10 07:06
题目链接
原题:
题目:如果CEO手下有很多总监,总监手下有很多总经理,依此类推。那么通过一个名字和一个头衔,要如何找到符合条件的人?用递归和LINQ实现。
解法:这明显是C#问题吧。C#我勉强懂点基本语法,LINQ则完全不会,所以我只能用递归了。
代码:
题目链接
原题:
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面试题 - 6337018766295040
- Careercup - Microsoft面试题 - 5428361417457664
- Careercup - Microsoft面试题 - 5188169901277184
- Careercup - Microsoft面试题 - 5680049562845184
- Careercup - Microsoft面试题 - 6282862240202752
- Careercup - Microsoft面试题 - 5485521224597504
- Careercup - Microsoft面试题 - 5173689888800768
- Careercup - Microsoft面试题 - 5672369481842688
- Careercup - Microsoft面试题 - 6314866323226624
- Careercup - Microsoft面试题 - 5718181884723200
- Careercup - Microsoft面试题 - 5917873302142976
- Careercup - Microsoft面试题 - 6751316000899072
- Careercup - Microsoft面试题 - 5752271719628800
- Careercup - Microsoft面试题 - 5799446021406720
- Careercup - Microsoft面试题 - 24313662
- Careercup - Microsoft面试题 - 5943729928011776
- Careercup - Microsoft面试题 - 24308662
- Careercup - Microsoft面试题 - 23123665
- Careercup - Microsoft面试题 - 6366101810184192
- Careercup - Microsoft面试题 - 5120588943196160