摘要: 题目: 输入两个整数序列 第一个序列表示栈的压入顺序,第二个序列是弹出序列。 判断第二个序列是否是该栈的弹出序列。 假设所有的入栈的数字均不相等。 解答: 阅读全文
posted @ 2019-02-12 15:30 林木声 阅读(173) 评论(0) 推荐(0)
摘要: 题目: Validate if a given string is numeric Some examples:"0" > true"0.1" >true"abc" > false 解答: 阅读全文
posted @ 2019-02-08 16:00 林木声 阅读(170) 评论(0) 推荐(0)
摘要: 1 private static final int maxDiv10 = Integer.MAX_VALUE / 10; 2 3 public int atoi(String str) { 4 int i = 0; 5 int n = str.length(); 6 // 首先忽略字符串前面的空格 7 while(i maxDiv10 || n... 阅读全文
posted @ 2019-02-02 18:10 林木声 阅读(158) 评论(0) 推荐(0)
摘要: 题目: Given an input string s, reverse the string word by word.For example, given s = "the sky is blue", return "blue is sky the" Example Questions Cand 阅读全文
posted @ 2019-02-02 14:37 林木声 阅读(137) 评论(0) 推荐(0)
摘要: 在一个字符串中寻找某个字串 阅读全文
posted @ 2019-02-01 17:26 林木声 阅读(759) 评论(0) 推荐(0)
摘要: 题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: 阅读全文
posted @ 2019-02-01 16:28 林木声 阅读(106) 评论(0) 推荐(0)
摘要: 题目: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the tw 阅读全文
posted @ 2019-02-01 14:18 林木声 阅读(146) 评论(0) 推荐(0)
摘要: Card类 从命令行读入5张牌,然后输出牌型 运行例子: 阅读全文
posted @ 2019-01-31 20:20 林木声 阅读(570) 评论(0) 推荐(0)
摘要: 题目: 假设把某股票的价格按照时间先后顺序存储在数组中,请问买卖股票一次可能获得的最大利润是多少? 例如:一只股票在某些时间节点的价格是{9,11,8,5,7,12,16,14}。 如果我们能在价格为5的时候买入并在价格16的时卖出,则能获得最大的利润。 思路: 我们定义函数diff(i)为当卖出价 阅读全文
posted @ 2019-01-31 15:48 林木声 阅读(292) 评论(0) 推荐(0)
摘要: 题目: 请定义一个队列并实现函数max得到队列里的最大值,要求函数max、push_back、pop_front的时间复杂度都是O(1) 思路: 利用一个双向队列存储当前队列中最大值以及之后可能的最大值。在定义题目要求功能的队列时,除了定义一个队列data存储数值,还要额外用一个队列maximum存 阅读全文
posted @ 2019-01-31 14:42 林木声 阅读(782) 评论(0) 推荐(0)