
leetcode
文章平均质量分 69
dancinglikelink
Mind drives matter.
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode - Array - 27. Remove Element(第一道题)
1.Problem description 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 w原创 2016-08-03 19:47:23 · 476 阅读 · 0 评论 -
※ Leetcode - Dynamic Programming - 53.Maximum Subarray(最大连续和)+152.Maximum Product Subarray(最大连续积)
1. Problem Description of 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原创 2016-08-08 15:20:33 · 561 阅读 · 0 评论 -
Leetcode - Dynamic Programming - 343. Integer Break(划分整数得到最大乘积)
1. Problem Description Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get. For原创 2016-08-22 18:57:23 · 544 阅读 · 0 评论 -
区间DP:POJ 2955括号匹配 + NYOJ 737 石子归并(一) + No.312 Burst Balloons
1.区间DP入门 —— POJ 2955 括号匹配 我们先看一道经典题目:给出一个字符串,仅含()[]四个字符,问整个字符串里最多有多少个匹配的括号。 Sample Input ((())) ()()() ([]]) )[)( ([][][) end Sample Output 6 6 4 0 6 2. My solution of POJ 2955 区间dp原创 2016-08-24 09:42:05 · 605 阅读 · 0 评论 -
※ Leetcode - Segment Tree - 307. Range Sum Query - Mutable (线段树+树状数组两种解法以及模板的常见问题解析)
1. Problem Description Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. The update(i, val) function modifies nums by updating the element at原创 2016-08-12 13:30:57 · 1345 阅读 · 0 评论 -
Leetcode - Dynamic Progr - 64. Minimum Path Sum(BFS+DP)
1. Problem Description Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only mov原创 2016-08-12 15:37:45 · 466 阅读 · 0 评论 -
Catalan数——卡特兰数
转载自hackbuteer1 Catalan数——卡特兰数 今天阿里淘宝笔试中碰到两道组合数学题,感觉非常亲切,但是笔试中失踪推导不出来 后来查了下,原来是Catalan数。悲剧啊,现在整理一下 一、Catalan数的定义令h(1)=1,Catalan数满足递归式:h(n) = h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1),n>=转载 2016-08-24 19:33:35 · 505 阅读 · 0 评论 -
Leetcode - String - 292. Nim Game (裸Bash博弈)
1. Problem Description You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes th原创 2016-08-12 20:37:40 · 402 阅读 · 0 评论 -
Leetcode - String - 344. Reverse String (3种写法)
1. Problem Description Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 反转字符串 2. My solution1(另开辟字符串存储) class Solutio原创 2016-08-12 16:56:46 · 553 阅读 · 0 评论 -
Leetcode - Brainteaser - 319. Bulb Switcher(规律题)
1. Problem Description There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if原创 2016-08-13 10:19:38 · 491 阅读 · 0 评论 -
Leetcode - Array - 1. Two Sum (水题,O[n]和O[n^2]实现)
1.Problem Description Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution.原创 2016-08-03 20:02:35 · 379 阅读 · 0 评论 -
Leetcode - Bit minipulation - 371. Sum of Two Integers(递归模拟位运算求和)
1. Problem Description 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. 什么?你说好简单?输出两个数的和? 2. My s原创 2016-08-13 12:39:37 · 456 阅读 · 0 评论 -
※ Leetcode - Array - 380. Insert Delete GetRandom O(1)(vector+map实现set)
1. Problem Description Design a data structure that supports all following operations in average O(1) time. insert(val): Inserts an item val to the set if not already present. remove(val): Remov原创 2016-08-06 15:58:39 · 1241 阅读 · 0 评论 -
Leetcode - Math -258. Add Digits(数位求和,规律题)
1. Problem Description Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1原创 2016-08-15 10:31:23 · 543 阅读 · 0 评论 -
Leetcode - Hash Table - 349+350 Intersection of Two Arrays(快速返回两数组重叠部分)
1. Problem Description Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result mu原创 2016-08-07 15:57:11 · 639 阅读 · 0 评论 -
※ Leetcode - Binary Search - 153. Find Minimum in Rotated Sorted Array(二分查找)
1. Problem Description Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assum原创 2016-08-07 15:53:32 · 401 阅读 · 0 评论 -
Leetcode - String - 383. Ransom Note(水题)
1. Problem Description Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed原创 2016-08-16 12:03:34 · 1009 阅读 · 0 评论 -
※ Leetcode - Tree - 226. Invert Binary Tree(反转二叉树 使用二级指针交换两个指针的地址)
1. Problem Description Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was in原创 2016-08-16 13:02:42 · 564 阅读 · 0 评论 -
Leetcode - Tree - 104. Maximum Depth of Binary Tree(DFS求二叉树最深深度)
1. Problem Description 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. 2. My solution原创 2016-08-16 13:12:29 · 661 阅读 · 0 评论 -
Leetcode - Array - 189. Rotate Array
1. Problem Description Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note: Try to come up原创 2016-08-04 19:43:08 · 348 阅读 · 0 评论 -
Leetcode - Array - 66. Plus One(简单模拟)
1. Problem Description Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list原创 2016-08-04 20:17:18 · 348 阅读 · 0 评论 -
※ Leetcode - Array - 219.Contains Duplicate II+217. Contains Duplicate(Map)
1. Problem Description Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j原创 2016-08-03 20:09:03 · 398 阅读 · 0 评论 -
※ Leetcode - Array - 88. Merge Sorted Array(快速归并两个有序数组)
1. Problem Description 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 equa原创 2016-08-04 19:50:54 · 453 阅读 · 0 评论 -
※ Leetcode - Array - 169. Majority Element(快速找出数组中出现过一半以上次数的数,3种写法)
1.7.1 Problem Description Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty原创 2016-08-05 16:28:14 · 988 阅读 · 0 评论 -
※ Leetcode - Array -Remove Duplicates from Sorted Array(就地有序数组去重)
1. Problem Description 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 m原创 2016-08-05 16:51:25 · 553 阅读 · 0 评论 -
Leetcode - Array - 118. Pascal's Triangle(杨辉三角)
1. Problem Description Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1原创 2016-08-05 19:04:05 · 522 阅读 · 0 评论 -
Leetcode - Array - 283. Move Zeroes(两个指针除去所有0)
1. Problem Description Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3,原创 2016-08-05 19:27:14 · 320 阅读 · 0 评论 -
Leetcode - Array - 162. Find Peak Element(水题)
1. Problem Description A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[i+1], find a peak element and return its index. The array may c原创 2016-08-06 11:52:49 · 388 阅读 · 0 评论 -
※ Leetcode - Dynamic Programming - 121. Best Time to Buy and Sell Stock(动态规划)
1. Problem Description 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 (ie, buy one and sell原创 2016-08-05 20:09:56 · 393 阅读 · 0 评论 -
※ Leetcode - Dynamic Programming - 119. Pascal's Triangle II(倒叙滚动数组求解杨辉三角第k行)
1. Problem Description Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) ex原创 2016-08-05 20:54:09 · 916 阅读 · 0 评论 -
Leetcode - Tree - 106. Construct Binary Tree from Inorder and Postorder Traversal(根据中序遍历和后序遍历重构二叉树)
1. Problem Description Given inorder and postorder traversal of a tree, construct the binary tree. 2. My solution 类似的题目还有105,是根据中序和前序重构二叉树。根据前序和后序是无法重构二叉树的,因为重构二叉树需要中序遍历顺序提供划分左右子树的方法。 Findro原创 2016-09-06 20:09:57 · 632 阅读 · 0 评论