
Leetcode
MAGDB
这个作者很懒,什么都没留下…
展开
-
14. Longest Common Prefix
原题:Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string “”.Example 1:Input: ["flower","flow","flight"]Output:..原创 2019-01-20 11:11:54 · 129 阅读 · 0 评论 -
198. House Robber
原题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 you from robbing each of them is that adjacent ho...原创 2019-08-13 21:18:43 · 102 阅读 · 0 评论 -
107. Binary Tree Level Order Traversal II
原题Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,15...原创 2019-08-19 21:26:05 · 112 阅读 · 0 评论 -
100. Same Tree
原题Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example...原创 2019-08-14 21:12:34 · 105 阅读 · 0 评论 -
215. Kth Largest Element in an Array
快速排序不清晰思路class Solution {public: void swap(int& a,int& b) { int c = a; a = b; b = c; } void quickSort(vector<int>& nums,int left,int right)...原创 2019-08-23 23:20:59 · 159 阅读 · 0 评论 -
70. Climbing Stairs
原题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 climb to the top?Note: Given n will be a positiv...原创 2019-08-11 22:54:49 · 97 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
原题Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of t...原创 2019-08-20 20:37:59 · 139 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree
原题Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no childr...原创 2019-08-15 22:17:36 · 130 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
原题Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock...原创 2019-08-12 20:49:15 · 109 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
原题Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1->...原创 2019-08-08 23:24:57 · 89 阅读 · 0 评论 -
28. Implement strStr()
原题:Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example ...原创 2019-08-01 20:40:13 · 104 阅读 · 0 评论 -
13. Roman to Integer
原题:Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-01-20 13:27:10 · 147 阅读 · 0 评论 -
53. Maximum Subarray
原题:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanat...原创 2019-08-02 23:27:47 · 94 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
原题:Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modi...原创 2019-07-30 22:05:10 · 140 阅读 · 0 评论 -
58. Length of Last Word
原题:Given a string s consists of upper/lower-case alphabets and empty space characters ’ ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is def...原创 2019-08-03 22:52:28 · 88 阅读 · 0 评论 -
27. Remove Element
原题:Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input a...原创 2019-07-31 20:18:40 · 98 阅读 · 0 评论 -
69. Sqrt(x)--
//二分法 超时了不知道对错int mySqrt(int x){long long i = 0;long long j = (x + 1)/2;while (i <= j){ long long mid = (i + j) / 2; long long sq = mid * mid; if (sq == x) return mid; else if...原创 2019-08-07 22:34:59 · 111 阅读 · 0 评论 -
67. Add Binary
char* addBinary(char* a, char* b) { int lena = strlen(a), lenb = strlen(b), carry = 0; int lenc = lena > lenb?lena:lenb; char * c = malloc(lenc+2); c[lenc+1] = '\0'; whi...原创 2019-08-05 19:19:51 · 102 阅读 · 0 评论 -
35. Search Insert Position
原题:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array...原创 2019-08-01 19:40:19 · 78 阅读 · 0 评论 -
997. Find the Town Judge
原题In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge.If the town judge exists, then:The town judge trusts nobody.Everybody (e...原创 2019-08-27 23:40:44 · 191 阅读 · 0 评论