leetcode
文章平均质量分 62
小雨润如酥
这个作者很懒,什么都没留下…
展开
-
leetcode 66:Plus One
原题:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The原创 2017-06-29 09:41:09 · 182 阅读 · 0 评论 -
leetcode 88:Merge Sorted Array
原题:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to h原创 2017-06-29 10:05:09 · 187 阅读 · 0 评论 -
leetcode 25:Reverse Nodes in k-Group(C)
原题:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the num原创 2017-06-20 09:55:10 · 302 阅读 · 0 评论 -
leetcode 67. Add Binary
原题:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".两个二进制字符串,按照二进制数的方式相加,返回一个二进制数组代码如下:char* addBinary(char* a, char* b)原创 2017-06-30 10:11:38 · 200 阅读 · 0 评论 -
leetcode 26:Remove Duplicates from Sorted Array (C)
原题目:Given a sorted array, 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 in原创 2017-06-21 09:28:16 · 218 阅读 · 0 评论 -
leetcode:504. Base 7
原题:Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note: The input will be in range of [-1e7, 1e7原创 2017-07-11 09:39:50 · 238 阅读 · 0 评论 -
leetcode 520. Detect Capital
原题: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 let原创 2017-07-11 09:48:49 · 153 阅读 · 0 评论 -
leetcode 27 Remove Element (C)
原题:Given an array and a value, 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 in place with constant me原创 2017-06-22 09:04:21 · 181 阅读 · 0 评论 -
leetcode 28. Implement strStr()
原题;Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.从字符串中找到最先出现匹配字符串needle的下标。上代码:int strStr(char* haystack,原创 2017-06-22 11:19:17 · 137 阅读 · 0 评论 -
leetcode 541. Reverse String II
原题:Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all原创 2017-07-12 09:39:33 · 280 阅读 · 0 评论 -
leetcode :455. Assign Cookies
原题:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum si原创 2017-07-12 09:49:58 · 154 阅读 · 0 评论 -
leetcode 101. Symmetric Tree
原题:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3原创 2017-07-04 09:48:49 · 138 阅读 · 0 评论 -
leetcode 461:Hamming Distance
原题:The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note:原创 2017-07-04 16:36:25 · 116 阅读 · 0 评论 -
leetcode 617:Merge Two Binary Trees
原题:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new原创 2017-07-04 16:56:31 · 152 阅读 · 0 评论 -
leetcode 561:Array Partition I
原题:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n a原创 2017-07-04 17:07:06 · 148 阅读 · 0 评论 -
leetcode 476: Number Complement
原题:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the原创 2017-07-04 17:42:12 · 203 阅读 · 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 LeetCo原创 2017-07-05 09:41:33 · 173 阅读 · 0 评论 -
leetcode 628:Maximum Product of Three Numbers
原题:Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24原创 2017-06-26 14:29:32 · 296 阅读 · 0 评论 -
leetcode 575. Distribute Candies
原题:Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distr原创 2017-07-05 10:18:54 · 127 阅读 · 0 评论 -
leetcode 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 t原创 2017-06-27 15:08:32 · 180 阅读 · 0 评论 -
leetcode 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:原创 2017-06-28 10:34:30 · 163 阅读 · 0 评论 -
leetcode 204. Count Primes
原题 给一个整数n 寻找下2-n有多少个质数代码如下:int countPrimes(int n) { int *flag; int result=0; if(n<=1) return result; flag=(int*)malloc(sizeof(int)*(n+1)); memset(flag,0,sizeof(int)*(n+原创 2017-07-20 10:52:31 · 139 阅读 · 0 评论 -
leetcode 551. Student Attendance Record I
原题:You are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent.'L' : Late.'P' : Present.A student原创 2017-07-20 11:22:46 · 198 阅读 · 0 评论 -
leetcode 415. Add Strings
原题:Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only di原创 2017-07-17 10:38:30 · 151 阅读 · 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.原创 2017-07-17 10:58:27 · 174 阅读 · 0 评论 -
leetcode 633. Sum of Square Numbers
原题:求一个数是不是两个整数的平方和。代码如下:bool judgeSquareSum(int c) { int limit = sqrt(c); for(int n=0;n<=limit;n++) { double test=sqrt(c-n*n); if(test-(int)test==0) retur原创 2017-07-18 09:56:33 · 996 阅读 · 0 评论 -
leetcode 278. First Bad Version
原题:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed bas原创 2017-07-21 15:43:08 · 148 阅读 · 0 评论 -
leetcode 190. Reverse Bits
原题:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as原创 2017-07-18 10:37:03 · 319 阅读 · 0 评论 -
leetcode 268. Missing Number
原题:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algori原创 2017-07-18 11:08:46 · 147 阅读 · 0 评论 -
leetcode 492. Construct the Rectangle
原题:492. Construct the RectanFor a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, you原创 2017-07-10 10:13:17 · 252 阅读 · 0 评论 -
leetcode 225. Implement Stack using Queues
原题:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Re原创 2017-07-10 10:41:38 · 172 阅读 · 0 评论 -
leetcode 496 Next Greater Element I
原题:You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of num原创 2017-07-10 14:43:47 · 183 阅读 · 0 评论 -
leetocde 374. Guess Number Higher or Lower
原题:We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the nu原创 2017-07-19 11:02:16 · 172 阅读 · 0 评论 -
leetcode 463. Island Perimeter
原题:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is co原创 2017-07-19 11:33:19 · 228 阅读 · 0 评论 -
leetcode 647. Palindromic Substrings
原题:Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even th原创 2017-08-08 09:49:57 · 282 阅读 · 0 评论 -
leetcode 653. Two Sum IV - Input is a BST
原题:Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.Example 1:Input: 5 / \ 3原创 2017-08-08 11:51:04 · 488 阅读 · 0 评论 -
leetcode 495. Teemo Attacking
原题:In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attacking ascending time series towards Ashe and the pois原创 2017-08-16 09:27:10 · 228 阅读 · 0 评论 -
leetcode 442. Find All Duplicates in an Array
原题:Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it w原创 2017-08-09 09:43:27 · 155 阅读 · 0 评论 -
leetcode 547. Friend Circles
原题:There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend原创 2017-08-16 11:31:44 · 158 阅读 · 0 评论 -
leetcode 643. Maximum Average Subarray I
原题:Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value.Example 1:原创 2017-07-25 15:36:06 · 182 阅读 · 0 评论