随笔分类 -  leetcode刷题

摘要:Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr... 阅读全文
posted @ 2015-07-29 22:25 小金乌会发光-Z&M 阅读(174) 评论(0) 推荐(0) 编辑
摘要:Design a stack that supports push, pop, top, and retrieving(检索) the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Rem... 阅读全文
posted @ 2015-07-28 22:29 小金乌会发光-Z&M 阅读(250) 评论(0) 推荐(0) 编辑
摘要:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a... 阅读全文
posted @ 2015-07-26 14:55 小金乌会发光-Z&M 阅读(427) 评论(0) 推荐(0) 编辑
摘要:Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.分析:题意即为 阶乘尾部的零(求n!中尾部为0的个数)思路... 阅读全文
posted @ 2015-07-26 13:31 小金乌会发光-Z&M 阅读(202) 评论(0) 推荐(0) 编辑
摘要:Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文
posted @ 2015-07-19 13:13 小金乌会发光-Z&M 阅读(220) 评论(0) 推荐(0) 编辑
摘要:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), return ... 阅读全文
posted @ 2015-07-19 11:05 小金乌会发光-Z&M 阅读(208) 评论(0) 推荐(0) 编辑
摘要:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit in... 阅读全文
posted @ 2015-07-19 10:29 小金乌会发光-Z&M 阅读(151) 评论(0) 推荐(0) 编辑
摘要:Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --... 阅读全文
posted @ 2015-07-18 22:04 小金乌会发光-Z&M 阅读(175) 评论(0) 推荐(0) 编辑
摘要:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?分析:题意为判断单链表是否为回文的。思路:首先想到的是 遍历一次单链表,... 阅读全文
posted @ 2015-07-17 17:13 小金乌会发光-Z&M 阅读(182) 评论(0) 推荐(0) 编辑
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ... 阅读全文
posted @ 2015-07-17 10:55 小金乌会发光-Z&M 阅读(192) 评论(0) 推荐(0) 编辑
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> ... 阅读全文
posted @ 2015-07-16 22:28 小金乌会发光-Z&M 阅读(206) 评论(0) 推荐(0) 编辑
摘要:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo... 阅读全文
posted @ 2015-07-16 13:36 小金乌会发光-Z&M 阅读(289) 评论(0) 推荐(0) 编辑
摘要:Isomorphic StringsGiven two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All... 阅读全文
posted @ 2015-07-11 23:45 小金乌会发光-Z&M 阅读(184) 评论(0) 推荐(0) 编辑
摘要:一、Duplicate EmailsWrite a SQL query to find all duplicate emails in a table namedPerson.+----+---------+| Id | Email |+----+---------+| 1 | a@b.com... 阅读全文
posted @ 2015-07-08 15:26 小金乌会发光-Z&M 阅读(346) 评论(0) 推荐(0) 编辑
摘要:一、Implement Stack using QueuesImplement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the ele... 阅读全文
posted @ 2015-07-08 13:31 小金乌会发光-Z&M 阅读(309) 评论(0) 推荐(0) 编辑
摘要:Given an integer, write a function to determine if it is a power of two.分析:这道题让我们判断一个数是否为2的次方数(而且要求时间和空间复杂度都为常数),那么对于这种玩数字的题,我们应该首先考虑位操作 Bit Manipulat... 阅读全文
posted @ 2015-07-06 12:58 小金乌会发光-Z&M 阅读(232) 评论(0) 推荐(0) 编辑
摘要:一、Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at le... 阅读全文
posted @ 2015-07-05 21:10 小金乌会发光-Z&M 阅读(330) 评论(0) 推荐(0) 编辑
摘要:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"].分析:题意为给定一... 阅读全文
posted @ 2015-07-05 17:01 小金乌会发光-Z&M 阅读(225) 评论(0) 推荐(0) 编辑
摘要:一、Rising Temperature Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) da 阅读全文
posted @ 2015-07-04 17:12 小金乌会发光-Z&M 阅读(236) 评论(0) 推荐(0) 编辑
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2015-06-20 16:24 小金乌会发光-Z&M 阅读(145) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示