LeetCode
jessir
这个作者很懒,什么都没留下…
展开
-
LeetCode1. Two Sum
LeetCode 1.Two Sum原创 2017-02-26 20:56:01 · 286 阅读 · 0 评论 -
Leetcode 35. Search Insert Position
题意:找到比前面的数大比后面的数小的位置插进去,返回插入的位置。 int searchInsert(vector<int>& nums, int target) { for (int i = 0; i < nums.size(); i++) { if (nums[i] >= target) { return i;原创 2017-06-05 10:45:38 · 236 阅读 · 0 评论 -
Leetcode 69. Sqrt(x)
这道题只是要求int型的x的int的开根号数,只要不断用二分就可以,不过要注意边界条件,比如最后当high-low==1的时候,用不用返回以及要怎么返回。代码如下:class Solution {public: int mySqrt(int x) { if(x <= 0) return 0; int low = 1; int high = x; int mi原创 2017-06-05 10:32:44 · 248 阅读 · 0 评论 -
14. Longest Common Prefix
题目就是找最长公共前缀,很简单,直接写代码:class Solution {public: string longestCommonPrefix(vector<string> &strs) { if(strs.empty()) return ""; else if(strs.size() == 1) retur原创 2017-05-30 14:12:16 · 200 阅读 · 0 评论 -
Leetcode 101. Symmetric Tree
题目描述如下: 解决思路:这道题是我在BFS分类中找的,所以就试图用广搜的想法来解决,关键思路就是 1、left对应right 2、left->left对应right->right 3、left->right对应right->left; 技巧就是设立两个队列,一个保存左边的元素,另一个保存右边的元素。代码如下:/** * Definition for a binary tree node原创 2017-04-24 11:27:48 · 349 阅读 · 0 评论 -
leetcode 112. Path Sum
题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and su原创 2017-05-14 23:14:47 · 206 阅读 · 0 评论 -
Leetcode 520
Leetcode 520题目: Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All lett原创 2017-05-14 20:39:59 · 254 阅读 · 0 评论 -
LeetCode 241. Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *. Example 1 Input原创 2017-03-26 23:21:33 · 301 阅读 · 0 评论 -
LeetCode 4. Median of Two Sorted Arrays
这道题很经典啊,它归类在分治算法里面,感觉和求一堆数中的第k大差不多,只不过这里是有两个已经排好序的数组,所以比较麻烦一些。整体的思路如下: 1、要求出两个数列的中间数,可以转换成求第k小(大)的数; 2、要求第k小的数,可以分为将第一个数列的k/2个数和第二个数列的k/2个数进行对比,小的那一个数列的左边k/2个数就可以丢弃了,如此递归下去,递归的终止条件为:(1)如果有一个数列的长度为0,则原创 2017-03-26 22:41:31 · 244 阅读 · 0 评论 -
LeetCode 537. Complex Number Multiplication(string转int,int转string)
题目:Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definition.Example 1: Input: “1+1i”, “1+1i” Output:原创 2017-03-30 19:45:21 · 453 阅读 · 0 评论 -
Leetcode 557. Reverse Words in a String III
题目:Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 1: Input: “Let’s take LeetCode contest”原创 2017-04-10 19:48:03 · 1626 阅读 · 0 评论 -
LeetCode 539. Minimum Time Difference
题目:Given a list of 24-hour clock time points in “Hour:Minutes” format, find the minimum minutes difference between any two time points in the list.Example 1: Input: [“23:59”,”00:00”] Output: 1 Note:原创 2017-03-30 13:45:15 · 326 阅读 · 0 评论 -
LeetCode 541. Reverse String II
这道题一开始看错了题目,以为只是把前2K个的k个字符反转就可以,后来wa了才发现是要把每一个2k个字符的前k个字符反转,改正了代码。class Solution {public: void inv(string &s, int t, int k){ int med = (k-t)/2 + t; for(int i = t; i <= med; i++)原创 2017-03-30 09:35:02 · 787 阅读 · 0 评论 -
LeetCode 53. Maximum Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. 例子:For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1]原创 2017-03-28 23:36:57 · 258 阅读 · 0 评论 -
LeetCode 7.Reverse Integer/LeetCode 9.Palindrome Number
问题描述:Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Note:The input is assumed to be a 32-bit signed integer. Your function should return 0 when the rever原创 2017-03-20 13:49:17 · 481 阅读 · 0 评论 -
欢迎使用CSDN-markdown编辑器
欢迎使用Markdown编辑器写博客本Markdown编辑器使用[StackEdit][6]修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用转载 2017-03-20 13:44:31 · 350 阅读 · 0 评论 -
Leetcode215. Kth Largest Element in an Array
这是一道分治的题目,去面网易的机器学习岗位的时候问了我这个问题,我那时候第一反应就是桶排序。。 ## 桶排序 ## 先附上桶排序的代码如下,应该注意两个地方:1、排序的数有可能是负数;2、排序的数有可能是重复的,比如[99 99],要找出第一大的数,这种情况对于判断第几大的时候要采用大于等于而不是直接用等于来判断。class Solution {public: int find原创 2017-03-05 22:48:33 · 350 阅读 · 0 评论 -
Leetcode240. 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 properties:Integers in each row are sorted in ascending from left to right. Integers in ea原创 2017-03-08 20:10:42 · 3088 阅读 · 0 评论 -
Leetcode 113. Path Sum II
题目描述: Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.For example: Given the below binary tree and sum = 22, 5 / \原创 2017-05-21 21:35:05 · 252 阅读 · 0 评论