leetcode&hihocoder
文章平均质量分 72
abpenguin
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode41First Missing Positive & hihocoder1040矩形判断(C++)
近期刷了leetcode的41题和hihocode的1040题,在做这两题的时候都用到了数组的方式,只不过作用有些不同。1、leetcode41 First Missing Positive这道题的题目是这样的:Given an unsorted integer array, find the first missing positive integer.For example原创 2016-08-03 16:14:26 · 508 阅读 · 0 评论 -
leetcode 347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].class Solution(object): def topKFrequent(self, nums, k):原创 2016-11-25 15:45:28 · 305 阅读 · 0 评论 -
leetcode 409. Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not con原创 2016-11-25 15:44:13 · 270 阅读 · 0 评论 -
leetcode 167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two number原创 2016-11-25 11:40:42 · 549 阅读 · 0 评论 -
leetcode 392. Is Subsequence
Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) strin原创 2016-11-25 15:42:21 · 235 阅读 · 0 评论 -
leetcode 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note:原创 2016-11-24 15:22:10 · 275 阅读 · 0 评论 -
leetcode 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot原创 2016-11-24 11:26:43 · 267 阅读 · 0 评论 -
leetcode 404 Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24原创 2016-11-24 11:25:31 · 289 阅读 · 0 评论 -
leetcode 273. Integer to English Words
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,123 -> "One Hundred Twenty Three"12345 -> "Twelve Thousan原创 2016-11-30 17:33:42 · 317 阅读 · 0 评论 -
leetcode 24 Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only constant s原创 2016-08-12 10:27:17 · 264 阅读 · 0 评论 -
leetcode 50 Pow(x, n)
Implement pow(x, n).以上就是这道题目的题干,看起来非常简单没有什么过多的要求,实际上也是用最简单的方法做的,但是这道题目需要注意的细节很多,解法如下:最简单的方法可以利用math库函数进行计算class Solution {public: double myPow(double x, int n) { return原创 2016-08-12 09:03:19 · 275 阅读 · 0 评论 -
leetcode 69 Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.这道题目是写int类型开平方的方法,这题的解法有很多,可以通过遍历来实现,我的方法还是和之前的一道题目相似,用二分查找的方式,这道题目一定还有更简单的方法,先说一下我的算法:class Solution {public: int mySqrt原创 2016-08-09 19:58:45 · 239 阅读 · 0 评论 -
leetcode 374 Guess Number Higher or Lower
题目要求:We are playing the Guess Game. The game is as follows:I pick a number from 1 ton. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number原创 2016-08-05 22:33:25 · 354 阅读 · 0 评论 -
leetcode 144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].# Definition for a binar原创 2016-11-25 16:14:47 · 304 阅读 · 0 评论
分享