随笔分类 -  leetcode

摘要:1、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 o 阅读全文
posted @ 2016-06-21 09:49 dylqt 阅读(122) 评论(0) 推荐(0)
摘要:Given an integer, write a function to determine if it is a power of two. Given an integer, write a function to determine if it is a power of two. Give 阅读全文
posted @ 2016-06-15 14:38 dylqt 阅读(144) 评论(0) 推荐(0)
摘要:Majority Element Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You ma 阅读全文
posted @ 2016-06-15 14:37 dylqt 阅读(111) 评论(0) 推荐(0)
摘要: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 is like: 阅读全文
posted @ 2016-06-15 14:37 dylqt 阅读(117) 评论(0) 推荐(0)
摘要:Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = "anagram", t = "nagaram", return true. 阅读全文
posted @ 2016-06-15 14:36 dylqt 阅读(125) 评论(0) 推荐(0)
摘要:You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you cl 阅读全文
posted @ 2016-06-15 14:36 dylqt 阅读(180) 评论(0) 推荐(0)
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc 阅读全文
posted @ 2016-06-15 14:35 dylqt 阅读(121) 评论(0) 推荐(0)
摘要:Implement int sqrt(int x). Compute and return the square root of x. 自己的代码: 1 int mySqrt(int x) { 2 if(x == 0 || x == 1) 3 return x; 4 int begin = 0; 5 阅读全文
posted @ 2016-02-21 11:11 dylqt 阅读(252) 评论(0) 推荐(0)
摘要:Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the... 阅读全文
posted @ 2016-01-19 10:29 dylqt 阅读(238) 评论(0) 推荐(0)
摘要:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which... 阅读全文
posted @ 2016-01-18 11:09 dylqt 阅读(315) 评论(0) 推荐(0)
摘要:A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message conta... 阅读全文
posted @ 2016-01-07 16:33 dylqt 阅读(131) 评论(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-11-07 20:18 dylqt 阅读(153) 评论(0) 推荐(0)
摘要:You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret number and ask your friend to guess it. Each time your ... 阅读全文
posted @ 2015-11-06 21:38 dylqt 阅读(212) 评论(0) 推荐(0)
摘要:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return... 阅读全文
posted @ 2015-11-06 09:14 dylqt 阅读(163) 评论(0) 推荐(0)
摘要:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题目大意是,在一个大的字符串haystack中找到一... 阅读全文
posted @ 2015-11-02 08:51 dylqt 阅读(143) 评论(0) 推荐(0)
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana... 阅读全文
posted @ 2015-11-01 09:43 dylqt 阅读(131) 评论(0) 推荐(0)
摘要:Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 v2) return 1; else if(v2 > v1) ... 阅读全文
posted @ 2015-10-31 19:31 dylqt 阅读(158) 评论(0) 推荐(0)
摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off ... 阅读全文
posted @ 2015-10-30 16:26 dylqt 阅读(125) 评论(0) 推荐(0)
摘要:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the c... 阅读全文
posted @ 2015-10-30 16:24 dylqt 阅读(101) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings.class Solution {public: string longestCommonPrefix(vector& st... 阅读全文
posted @ 2015-10-30 09:05 dylqt 阅读(97) 评论(0) 推荐(0)