摘要: Problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input woul 阅读全文
posted @ 2016-12-28 11:58 yrwang 阅读(86) 评论(0) 推荐(0) 编辑
摘要: Problem: Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Example: 本题的第一想法是开一个字母表计数 阅读全文
posted @ 2016-12-28 06:05 yrwang 阅读(151) 评论(0) 推荐(0) 编辑
摘要: Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at 阅读全文
posted @ 2016-11-20 10:58 yrwang 阅读(144) 评论(0) 推荐(0) 编辑
摘要: Problem: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process 阅读全文
posted @ 2016-11-10 01:58 yrwang 阅读(132) 评论(0) 推荐(0) 编辑
摘要: Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the f 阅读全文
posted @ 2016-11-03 08:51 yrwang 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 最原始的方法:先排序,然后从头查找。若nums[i] = nums[i] + 1则为一对相同的数,i = i + 2,继续判断。若nums[i] != nums[i] + 1,则输出nums[i]。需注意不要越界! 通过参考别人的解题报告发现,可以使用异或运算:对所有元素做异或运算,其结果为那个出现 阅读全文
posted @ 2016-11-02 08:08 yrwang 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 此题为技巧题,需知道Nim Game的Wining Strange,即在自己的局中,如果剩余数目为4的倍数,则不可能取胜。因此检测N是否为4的倍数即可。Background参见http://www.cdf.toronto.edu/~ajr/270/probsess/03/strategy.html 阅读全文
posted @ 2016-11-02 05:45 yrwang 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Problem: Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of 阅读全文
posted @ 2016-10-28 12:02 yrwang 阅读(154) 评论(1) 推荐(0) 编辑
摘要: Problem: Write a function that takes a string as input and returns the string reversed. 此题一般思路为:在原数组上直接对s[i]以及s[len-i-1]进行调换即可。 阅读全文
posted @ 2016-10-28 10:37 yrwang 阅读(86) 评论(0) 推荐(0) 编辑