摘要:最近买了很多数学方面的书,从《天才引导的历程》,《什么是数学》到《费马大定理》,《黎曼猜想漫谈》。基本上是科普性质,但也需要一定的数学知识和耐心才能读进去。 数学跟我的工作没有太多的联系,只是为了探求智力上的极限,似乎这慢慢成为我娱乐的一种方式。在思考当中我找不到比数学问题更能考验纯粹思维能力的东西了。 在数学家的世界里,用几个月甚至数年的时光去搞明白一些问题好像是很平常的事情。即使是具...
阅读全文
摘要:Encode a string by counting the consecutive letter. (i.e., "aaaabbxxxyyz" might become "a4b2x3y2z1"). 分析: 这个问题是一个基本的数据压缩算法,将相邻的字符计数存储。解法没有什么特别需要注意的地方,按部就班的实现代码就可以了。 class Solution: # @param s,...
阅读全文
摘要:Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose a sorted array is rotated at some pivot unknown ...
阅读全文
摘要:Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cas...
阅读全文
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactl...
阅读全文
摘要:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in a...
阅读全文
摘要:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must...
阅读全文
摘要: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 two numbers such that they add up to the target, whe...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. 分析: 对一组字符串找到最长公共前缀。 因为只是找前缀所以可以以第一个字符串为基础,按个字符与其它字符串比较,直到有字符串已经遍历完或者碰到不一致的字符,返回到当前为止第一个字符串的前缀即可。 class Solution...
阅读全文
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exists in the arr...
阅读全文
摘要:读《费马大定理》这本书的时候,第二章一开始引用了一段文字,出自阿瑟•波格斯(Arthur Porges)的《魔王与西蒙•弗拉格》“你听我说,”魔王吐露说,“就连其它星球上最出色的数学家——远远超出你们——也没能解开这个谜!嗨,土星上有个家伙——他看上去像是踩着高跷的蘑菇——能用心算解偏微分方程,就连...
阅读全文