随笔分类 -  Algorithm

上一页 1 2 3 4 5 6 7 ··· 16 下一页
classic algorithm, problem
摘要:>Given an integer, write a function to determine if it is a power of two.这是计算数中1的个数的简版,如果是2的幂的话,二进制中应该只有一个bit为1,即1的count=1。所以这里就不需要用循环了,一次判断即可。但是入参是有符... 阅读全文
posted @ 2015-07-06 09:57 卖程序的小歪 阅读(192) 评论(0) 推荐(0)
摘要:```The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out i... 阅读全文
posted @ 2015-07-05 15:35 卖程序的小歪 阅读(146) 评论(0) 推荐(0)
摘要:>A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are giv... 阅读全文
posted @ 2015-07-04 16:38 卖程序的小歪 阅读(307) 评论(0) 推荐(0)
摘要:```Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST... 阅读全文
posted @ 2015-07-03 16:50 卖程序的小歪 阅读(1001) 评论(0) 推荐(0)
摘要:```Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattene... 阅读全文
posted @ 2015-06-30 21:18 卖程序的小歪 阅读(140) 评论(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"].```java... 阅读全文
posted @ 2015-06-26 11:11 卖程序的小歪 阅读(121) 评论(0) 推荐(0)
摘要:##DESCIRPTIONImplement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, /... 阅读全文
posted @ 2015-06-24 10:41 卖程序的小歪 阅读(143) 评论(0) 推荐(0)
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.强行解:inline bool valueSame(double a, double b) { re... 阅读全文
posted @ 2015-06-16 11:31 卖程序的小歪 阅读(212) 评论(0) 推荐(0)
摘要:Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can f... 阅读全文
posted @ 2015-06-14 17:15 卖程序的小歪 阅读(192) 评论(0) 推荐(0)
摘要:Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be changed... 阅读全文
posted @ 2015-06-14 01:18 卖程序的小歪 阅读(161) 评论(0) 推荐(0)
摘要:Given two words (beginWordandendWord), and a dictionary, find the length of shortest transformation sequence frombeginWordtoendWord, such that:Only on... 阅读全文
posted @ 2015-06-13 23:34 卖程序的小歪 阅读(220) 评论(0) 推荐(0)
摘要:Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjac... 阅读全文
posted @ 2015-06-13 18:53 卖程序的小歪 阅读(163) 评论(0) 推荐(0)
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node... 阅读全文
posted @ 2015-06-12 17:59 卖程序的小歪 阅读(151) 评论(0) 推荐(0)
摘要:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top()... 阅读全文
posted @ 2015-06-12 17:47 卖程序的小歪 阅读(148) 评论(0) 推荐(0)
摘要:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open(and closing parentheses), the plus+or minus... 阅读全文
posted @ 2015-06-10 01:16 卖程序的小歪 阅读(971) 评论(0) 推荐(0)
摘要:Find the total area covered by tworectilinearrectangles in a2Dplane.Each rectangle is defined by its bottom left corner and top right corner as shown ... 阅读全文
posted @ 2015-06-09 00:57 卖程序的小歪 阅读(202) 评论(0) 推荐(0)
摘要:Given acompletebinary tree, count the number of nodes.Definition of a complete binary tree fromWikipedia:In a complete binary tree every level, except... 阅读全文
posted @ 2015-06-07 13:56 卖程序的小歪 阅读(2014) 评论(0) 推荐(0)
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matr... 阅读全文
posted @ 2015-06-07 13:41 卖程序的小歪 阅读(170) 评论(0) 推荐(0)
摘要:Given an array of integers, find out whether there are two distinct indicesiandjin the array such that the difference betweennums[i]andnums[j]is at mo... 阅读全文
posted @ 2015-06-07 11:31 卖程序的小歪 阅读(305) 评论(0) 推荐(0)
摘要:Given an array of integers and an integerk, find out whether there there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and the d... 阅读全文
posted @ 2015-06-07 00:00 卖程序的小歪 阅读(160) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 16 下一页