Ibibo Interview Question Software Engineer / Developers
来源:互联网 发布:淘宝网最小手机 编辑:程序博客网 时间:2024/05/11 20:22
原题是:
Given a string that contains exactly a single pair of parenthesis, return parenthesis and their contents, so "xyz(abc)123" yields "(abc)". etc.
Conditions:
1)No variable allowed
2)Collections not allowed
3)Regex, String.indexOf() not allowed.
大意就是不用任何变量、正则式来求出给定字符串有()的字符串子集。
如果可以使用局部变量的话,这道题是O(N)的解法,只要记住(的位置即可,但是现在不能。
一个解法是 如果字符串第一个不是(就++,最后一个不是)就--;string有这个sbustr可用,用递归来做就可以了。
#include <iostream>#include <string>using namespace std;string findparenthesis(string s){if (s.empty()){return "";}if (s[0] == '('){if (s[s.size()-1] == ')'){return s;}else{return findparenthesis(s.substr(0, s.length()-1));}} else{return findparenthesis(s.substr(1, s.length()-1));}}int main(){printf("%s", findparenthesis("xyz(abc)123").c_str());}
0 0
- Ibibo Interview Question Software Engineer / Developers
- Google Interview Question Software Engineer / Developers
- Google Interview Questions: Software Engineer
- 100 Interview Questions for Software Developers
- software engineer
- Interview question
- interview question
- interview question
- interview question
- interview-question
- 100 Interview Questions for Software Developers-软件开发者面试百问
- 100 Interview Questions for Software Developers 面试题 超级的经典
- Embedded Software Design Engineer
- (Senior) Software Engineer
- such a software engineer
- Principal Software Engineer
- Consultant Software Quality Engineer
- Junior Software QA Engineer
- 浮点精度
- 里氏替换原则
- JdbcTemplate及报错'dataSource' or 'jdbcTemplate' is required
- 测试一下机器
- Windows下Hello Word程序
- Ibibo Interview Question Software Engineer / Developers
- STL: string
- LeetCode 65. Add Binary
- 2014年7月7日-7月13日计划及执行情况(共36小时,剩4376小时
- Reverse Linked List II
- Add Two Numbers
- Java 5|6 并发包介绍
- 另眼相看“那些争议最大的编程观点”
- Python 提取Twitter特定话题中转载tweet的用户