![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 67
紫魔戒
无无
展开
-
LeetCode 371.Sum of Two Integers
LeetCode 371.Sum of Two Integers原创 2017-02-25 19:09:32 · 268 阅读 · 0 评论 -
LeetCode 53. Maximum Subarray
53. Maximum Subarraymy program:class Solution {public: int maxSubArray(vector<int>& nums) { int result = nums[0]; int sum = 0; for (int i = 0; i<nums.size(); ++i) {原创 2017-03-01 12:54:02 · 323 阅读 · 0 评论 -
Proving NP-completeness
Proving NP-completeness by generalization. For each of the problems below, prove that it is NP-complete by showing that it is a generalization of some NP-complete problem we have seen in this chapter.原创 2017-06-30 19:49:44 · 707 阅读 · 0 评论 -
LeetCode207. Course Schedule
DescriptionThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed原创 2017-06-19 16:43:01 · 265 阅读 · 0 评论 -
LeetCode459. Repeated Substring Pattern
今天在做C语言经典实例100题中遇到的一题,其中的方法很值得学习,第一种是我自己所编写的程序,方法很一般,是个人都能想到。而第二种方法则非常巧妙。 32题目:删除一个字符串中的指定字母,如:字符串 “aca”,删除其中的 a 字母。#include <stdio.h>#include <string.h>int main(){ char str[100]; char c;原创 2016-06-02 15:03:44 · 238 阅读 · 0 评论 -
LeetCode560. Subarray Sum Equals K
DescriptionGiven an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Input:nums = [1,1,1], k = 2 Output: 2 Note原创 2017-05-21 19:51:26 · 290 阅读 · 0 评论 -
LeetCode566. Reshape the Matrix
DescriptionIn MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a t原创 2017-05-20 19:31:17 · 243 阅读 · 0 评论 -
LeetCode300. Longest Increasing Subsequence
DescriptionGiven an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3,原创 2017-05-30 20:20:18 · 194 阅读 · 0 评论 -
LeetCode581. Shortest Unsorted Continuous Subarray
DescriptionGiven an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need原创 2017-05-26 18:15:46 · 190 阅读 · 0 评论 -
LeetCode 69. Sqrt(x)
DescriptionImplement int sqrt(int x). Compute and return the square root of x.my program 思路:看似很简单的问题,可以不断的优化算法,最开始容易想到的是定义一个num使其递增,直到num*num > x,可是未考虑num*num越界的问题,后更改判断条件为num <= x/num,可以消除越界问题。但是此算原创 2017-05-07 20:25:05 · 252 阅读 · 0 评论 -
LeetCode 128. Longest Consecutive Sequence
DescriptionGiven an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is原创 2017-05-15 15:17:18 · 226 阅读 · 0 评论 -
LeetCode543. Diameter of Binary Tree
DescriptionGiven a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path ma原创 2017-05-04 12:56:40 · 277 阅读 · 0 评论 -
LeetCode 34. Search for a Range
DescriptionGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If th原创 2017-03-19 20:11:35 · 262 阅读 · 0 评论 -
LeetCode119. Pascal's Triangle II
DescriptionGiven an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].my programclass Solution {public: vector<int> getRow(int rowIndex) { ve原创 2017-04-23 22:15:00 · 206 阅读 · 0 评论 -
LeetCode447. Number of Boomerangs
DescriptionGiven n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k(the order原创 2017-04-16 17:50:41 · 266 阅读 · 0 评论 -
LeetCode455. Assign Cookies
DescriptionAssume 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 siz原创 2017-03-26 23:54:12 · 171 阅读 · 0 评论 -
LeetCode406. Queue Reconstruction by Height Add to List
DescriptionSuppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in fron原创 2017-03-31 16:40:17 · 181 阅读 · 0 评论 -
LeetCode: 338. Counting Bits
338. Counting BitsDescriptionGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array原创 2017-03-11 11:53:37 · 243 阅读 · 0 评论