
C++学习
七仔xu
这个作者很懒,什么都没留下…
展开
-
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 as large as poss...原创 2018-03-08 22:44:50 · 328 阅读 · 0 评论 -
334.leetcode Increasing Triplet Subsequence(medium)[巧妙的方法减少时间与空间复杂度]
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, k such that arr[i] ar原创 2016-10-07 21:47:16 · 264 阅读 · 0 评论 -
397.leetcode Integer Replacement(easy)[数字处理 溢出]
Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1.What is the minimum number o原创 2016-10-07 21:11:45 · 285 阅读 · 0 评论 -
409.leetcode Longest Palindrome(easy)[字符串处理 最长回文]
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not con原创 2016-10-07 16:48:57 · 332 阅读 · 0 评论 -
371.leetcode Sum of Two Integers(easy)[异或 与运算处理]
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.两个数相加但是不能用+、-运算符则考虑从位运算的角度来解决问题,观察二进制加法的特点,如果没有进位的时候结果是原创 2016-10-07 16:00:05 · 239 阅读 · 0 评论 -
404.leetcode Sum of Left Leaves(easy)[二叉树 递归]
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. Return 24原创 2016-10-07 15:34:18 · 223 阅读 · 0 评论 -
389.leetcode Find the Difference(easy)[字符串处理]
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was原创 2016-10-07 15:21:51 · 216 阅读 · 0 评论 -
96.leetcode Unique Binary Search Trees(meidum)[动态规划]
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2016-09-07 21:43:10 · 256 阅读 · 0 评论 -
392.leetcode Is Subsequence (medium)[判断一个字符串是否是另一个字符串的子串]
Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) strin原创 2016-09-07 21:05:39 · 1946 阅读 · 0 评论 -
401.leetcode Binary Watch(easy)[递归回溯]
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant bit o原创 2016-09-22 20:48:24 · 587 阅读 · 0 评论 -
315.leetcode Count of Smaller Numbers After Self(hard)[利用二分查找 空间换取时间的思想]
You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].Example原创 2016-10-08 21:08:56 · 391 阅读 · 0 评论 -
264.leetcode Ugly Number II(medium)[寻找第N个丑数]
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first原创 2016-09-22 19:52:42 · 592 阅读 · 0 评论 -
124.leetcode Binary Tree Maximum Path Sum(hard)[先序遍历]
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The原创 2016-08-26 21:30:05 · 410 阅读 · 0 评论 -
129.leetcode Sum Root to Leaf Numbers(medium)[深度遍历DFS]
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota原创 2016-08-26 21:00:12 · 387 阅读 · 0 评论 -
113.leetcode Path Sum II(meidum)[DFS加回溯 ]
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 / \原创 2016-08-26 16:59:14 · 412 阅读 · 0 评论 -
396.leetcode Rotate Function(easy)[找规律]
Given an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:原创 2016-10-08 19:46:41 · 249 阅读 · 0 评论 -
455.leetcode Assign Cookies(easy)[数组处理]
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 size of a c原创 2016-12-16 15:59:25 · 397 阅读 · 0 评论 -
leetcode 434.Number of Segments in a String(easy)[分割字符串]
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.Please note that the string does not contain any non-printable characters.原创 2016-12-17 17:24:55 · 367 阅读 · 0 评论 -
leetcode 413. Arithmetic Slices(medium)
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequenc原创 2017-04-21 15:56:28 · 396 阅读 · 0 评论 -
leetcode 557. Reverse Words in a String III(easy)
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 contes原创 2017-04-17 16:28:09 · 453 阅读 · 0 评论 -
leetcode 506. Relative Ranks(easy)
Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".Example 1:In原创 2017-04-20 15:12:08 · 319 阅读 · 0 评论 -
leetcode 541. Reverse String II(easy)
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 of th原创 2017-04-20 11:46:53 · 433 阅读 · 0 评论 -
leetcode 504. Base 7(easy)
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, 1e原创 2017-04-20 10:20:24 · 336 阅读 · 0 评论 -
leetcode 492. Construct the Rectangle(easy)
Total Accepted: 14611Total Submissions: 29825Difficulty: EasyContributors:love_FawnFor a web developer, it is very important to know how to design a web page's size. So, given a specific recta原创 2017-04-19 15:31:22 · 349 阅读 · 1 评论 -
leetcode 530. Minimum Absolute Difference in BST(easy)
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input: 1 \ 3 / 2Output:1Explanation:Th原创 2017-04-18 16:02:53 · 258 阅读 · 0 评论 -
leetcode 520. Detect Capital(easy)
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 letters in t原创 2017-04-18 15:44:31 · 366 阅读 · 0 评论 -
leetcode 485. Max Consecutive Ones(easy)
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutiv原创 2017-04-18 15:25:54 · 285 阅读 · 0 评论 -
leetcode 500. Keyboard Row(easy)
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.Example 1:Input: ["Hello", "Alaska", "Da原创 2017-04-17 17:01:46 · 290 阅读 · 0 评论 -
leetcode.55.Jump Game(medium)[贪心算法]
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2016-12-23 16:23:13 · 400 阅读 · 0 评论 -
leetcode 461.Hamming Distance(easy)[位运算]
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:0 ≤ x,原创 2016-12-21 11:37:04 · 414 阅读 · 0 评论 -
463.leetcode Island Perimeter(easy)[二维数组处理]
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 completely原创 2016-12-14 16:43:01 · 380 阅读 · 0 评论 -
412.leetciode Fizz Buzz(easy)[字符串 整数处理]
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.原创 2016-12-14 15:58:44 · 246 阅读 · 0 评论 -
24.leetcode Merge k Sorted Lists(hard)[归并k个有序链表]
其实整体思想和归并k个有序数组是一样的,有三种方法,效率最慢的是两个有序链表和并之后再与其他链表合并,需要合并n-1次。第二种方法是两两一组分别归并,第三种方法是采用一个k大小的堆,刚开始的时候将每个链表的第一个元素都放入k的最小堆中,那么就可以直接得到k中最小的值,再将k中刚取出的最小值的下一个节点加入堆中,直到所有的元素都处理完成。/** * Definition for singly-原创 2016-08-26 15:55:36 · 511 阅读 · 0 评论 -
83.leetcode Remove Duplicates from Sorted List(easy)[链表删除重复部分]
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.class Solution {public原创 2016-08-26 11:38:28 · 333 阅读 · 0 评论 -
143.leetcode Reorder List (medium)[链表调整]
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t原创 2016-08-23 21:51:14 · 248 阅读 · 0 评论 -
93.leetcode Restore IP Addresses(medium)[回溯 DFS]
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2016-08-23 20:49:46 · 974 阅读 · 0 评论 -
4.leetcode Median of Two Sorted Arrays(medium)[求两个数组的中位数]
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 =原创 2016-08-23 16:21:55 · 439 阅读 · 0 评论 -
142.leetcode Linked List Cycle II(medium)[有环链表]
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?原创 2016-08-22 21:36:21 · 229 阅读 · 0 评论 -
378.leetcode Kth Smallest Element in a Sorted Matrix(medium)[堆求第K小的 ]
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not原创 2016-08-22 20:26:07 · 279 阅读 · 0 评论 -
387.leetcode First Unique Character in a String(easy)[统计字符串字符次数]
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.题目要找第一个没有重复的字原创 2016-08-22 19:51:53 · 796 阅读 · 0 评论