上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 43 下一页
摘要: 在黑板上写下50个数字:1至50。在接下来的49轮操作中,每次做如下操作:选取两个黑板上的数字a和b,擦去,在黑板上写|b-a|。请问最后一次动作之后剩下的数字可能是什么?为什么?(不用写代码,不写原因不得分)(阿里巴巴笔试题)将题目通用化,即变成给定1..n这n个数字,操作到最后剩下的数字可能是什么。则原题即是n=50的特例。首先我们有结论1:假设操作1..n,最后剩下的可能数字的个数为k,则操作1..(n+1)时,剩下数字的个数将大于等于k。这个结论简单的用反证法证明下——假设存在n,使得操作1..n时,剩下的数字个数k,操作1..(n+1)剩下可能数字的个数为p,且k>p。则令1. 阅读全文
posted @ 2013-10-07 21:38 feiling 阅读(1060) 评论(0) 推荐(0) 编辑
摘要: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.[解题思路]1.和clone graph那题差不多,使用一个map来保存已经创建好的node。第一步:先复制原始链表中的节点,用next指针链接起来,在复制节点时放入map中第二步:设置每个节点的random指针空间复杂度为O(n),时间复杂度为O(n)Accepted Co 阅读全文
posted @ 2013-10-05 15:42 feiling 阅读(848) 评论(2) 推荐(0) 编辑
摘要: Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.[解题思路]图的遍历有两种方式,BFS和DFS这里使用BFS来解本题,BFS需要使用queue来保存neighbors但这里有个问题,在clone一个节点时我们需要clone它的neighbors,而邻居节点有的已经存在,有的未存在,如何进行区分?这里我们使用Map来进行区分,Map的key值为原来的node,value为新clone的node,当发现一个node未在map中时说明这个node还未被clone,将 阅读全文
posted @ 2013-10-04 21:26 feiling 阅读(1077) 评论(0) 推荐(0) 编辑
摘要: 程序设计语言的指令都可以访问虚存区域中的程序和数据,可以通过给每个进程一个唯一的不重叠的虚存空间来实现进程隔离;可以通过使两个虚存空间的一部分重叠来实现内存共享ref:操作系统精髓与设计原理第5版 p52 阅读全文
posted @ 2013-10-04 13:09 feiling 阅读(902) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?[解题思路]人生最悲催的事是刚面完试,leetcode就把我面试的题目给刷出来了。。。。1.O(n) time complexity O(n) space complexity cou 阅读全文
posted @ 2013-10-04 12:00 feiling 阅读(3275) 评论(0) 推荐(1) 编辑
摘要: There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from stationito its next station (i+1). You begin the journey with an empty tank at one of the gas stations.Return the starting gas 阅读全文
posted @ 2013-10-03 11:37 feiling 阅读(865) 评论(0) 推荐(0) 编辑
摘要: There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children with a higher rating get more candies than their neighbors.What is the minimum candies you mu 阅读全文
posted @ 2013-10-03 10:39 feiling 阅读(1324) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearstwiceexcept for one. Find that single one.Could you implement it without using extra memory?[解题思路]以前看书时遇到过,一个数组中有一个元素出现一次,其他每个元素都出现两次要求空间复杂度为O(1)由于两个相同的元素异或的结果为0,而0^a==a,将数组中所有元素都进行异或,得到结果就是只出现一次的元素 1 public class Solution { 2 public int singleNum... 阅读全文
posted @ 2013-10-02 20:57 feiling 阅读(1080) 评论(2) 推荐(0) 编辑
摘要: Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog"dict=["hot",&q 阅读全文
posted @ 2013-09-17 11:08 feiling 阅读(2427) 评论(1) 推荐(0) 编辑
摘要: 基本问题:1.两个链表中的第一个公共结点[解题思路]a.先求得两个链表的长度,得到链表长度差db.根据链表长度差,首先让长链表的指针先走d-1步,之后两个指针一起走,发现相同结点时就是公共结点 int len1 = 0, len2 = 0; ListNode p1 = head1, p2 = head2; while (p1 != null) { len1++; p1 = p1.next; } while (p2 != null) { len2++; ... 阅读全文
posted @ 2013-09-13 14:11 feiling 阅读(369) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 43 下一页