LeetCode H-Index

LeetCode H-Index题目 Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the resea...

2016-01-08 15:27:15

阅读数:446

评论数:7

LeetCode Add Digits

LeetCode Add Digits题目 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: ...

2016-01-07 00:27:08

阅读数:324

评论数:0

LeetCode Ugly Number

LeetCode Ugly Number题目 Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factor...

2016-01-07 00:25:34

阅读数:347

评论数:0

LeetCode Missing Number

LeetCode Missing Number题目 Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. ...

2016-01-06 23:26:59

阅读数:289

评论数:0

LeetCode Search a 2D Matrix II

LeetCode Search a 2D Matrix II题目 Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 2...

2016-01-06 23:25:01

阅读数:261

评论数:0

LeetCode Binary Tree Paths

题目 Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-...

2016-01-06 23:21:59

阅读数:225

评论数:0

LeetCode Different Ways to Add Parentheses

LeetCode Different Ways to Add Parentheses题目 Given a string of numbers and operators, return all possible results from computing all the differe...

2016-01-05 18:43:08

阅读数:263

评论数:0

LeetCode Search a 2D Matrix II

LeetCode Search a 2D Matrix II题目 Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following propertie...

2016-01-05 16:51:09

阅读数:229

评论数:0

LeetCode Shortest Word Distance III

LeetCode Shortest Word Distance III题目服务器抽风无法上传图片。 This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same...

2015-11-26 15:13:03

阅读数:295

评论数:0

LeetCode Shortest Word Distance II

LeetCode Shortest Word Distance II题目思路跟上一题一样,但是在这题的背景下,求最短距离的函数将会被调用多次。因此我们可以先把字符串的每个位置都记录下来,这样找最短距离的时候就好很多。而且,记录位置的时候都是有序的,这样,在求最短距离的时候就类似于归并排序,只需要O...

2015-11-26 14:53:01

阅读数:413

评论数:0

LeetCode Shortest Word Distance

LeetCode Shortest Word Distance题目思路直接对两个目标字符串进行定位,然后更新最小距离即可。O(n),注意循环最好倒过来,这是因为这样的话words.size()方法只需要调用一次,如果写成i < words.size()的话会增加不必要的耗时。代码class ...

2015-11-26 14:03:27

阅读数:287

评论数:0

LeetCode Valid Anagram

啊飒飒大

2015-11-24 09:00:44

阅读数:340

评论数:0

LeetCode Summary Ranges

Summary Ranges题目思路直接做代码class Solution { public: vector<string> summaryRanges(vector<int>& nums) { vector<string> an...

2015-07-12 08:43:22

阅读数:580

评论数:0

LeetCode OJ Basic Calculator II

Basic Calculator II题目思路和这个一样:Basic Calculator I代码class ExpressionTransformation { public: string trans_to_postfix_expression_to_s(string); // 将得...

2015-07-11 08:05:14

阅读数:674

评论数:0

LeetCode Basic Calculator

LeetCode Basic Calculator题目思路其实就是前中后缀表达式的转换和计算; 以前写过一个类:前中后缀表达式计算类 但是由于类有点大,只能拆开交(为了检测正确性);代码转为前缀计算class ExpressionTransformation { public: str...

2015-06-13 09:36:07

阅读数:1393

评论数:0

LeetCode Implement Stack using Queues

LeetCode Implement Stack using Queues题目思路就是个模拟; 如果把队头当做栈顶,只是push函数比较麻烦; 如果把队尾当做栈顶,pop和top函数都比较麻烦; 这里采用第一种方法;代码class Stack { public: void push(...

2015-06-13 09:35:40

阅读数:791

评论数:0

LeetCode Invert Binary Tree

LeetCode Invert Binary Tree题目思路没什么思路可言; 真不敢相信他写不出;代码struct TreeNode* invertTree(struct TreeNode* root) { if (root == NULL) return root; inve...

2015-06-13 09:34:57

阅读数:1891

评论数:0

LeetCode Rectangle Area

LeetCode Rectangle Area题目思路刚开始自己写别提WA多少遍了; 后来看到标达真的被惊讶到了; 代码可以这么美;代码自己的#define min(A, B) (A > B ? B : A)bool pointInRectangle(int px, int py, in...

2015-06-13 09:34:33

阅读数:849

评论数:0

LeetCode Count Complete Tree Nodes

LeetCode Count Complete Tree Nodes题目思路这个树会灰常的大; 先沿着左右两遍计算深度,如果深度一样直接代公式算; 如果深度不一样,那就找最下面一层的断点;代码int maxD, num;int calDeepFromRight(struct TreeNode*...

2015-06-07 09:32:19

阅读数:1081

评论数:0

LeetCode Contains Duplicate III

LeetCode Contains Duplicate III题目思路我的方法是先用一个结构体,存下每个数字的值和其原坐标; 然后根据值大小排序; 接着遍历每一个数字num[i].val; 利用二分查找找到刚好比num[i].val - t - 1大的数字的坐标; 然后根据坐标判断是否存在...

2015-06-06 08:46:09

阅读数:1284

评论数:0

提示
确定要删除当前文章?
取消 删除
关闭
关闭