- 博客(42)
- 收藏
- 关注
原创 leetcode(279). Perfect Squares
problem Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n. For example, given n = 12, return 3 because 12 = 4 + 4 + 4; g
2017-08-23 23:52:04 251
原创 leetcode(310). Minimum Height Trees
problem For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height
2017-08-23 20:11:06 278
原创 图的最短路径算法
最短路径问题是图论研究中的一个经典算法问题,旨在寻找图(由结点和路径组成的)中两结点之间的最短路径。算法具体的形式包括:确定起点的最短路径问题 - 即已知起始结点,求最短路径的问题。适合使用Dijkstra算法。确定终点的最短路径问题 - 与确定起点的问题相反,该问题是已知终结结点,求最短路径的问题。在无向图中该问题与确定起点的问题完全等同,在有向图中该问题等同于把所有路径方向反转的确定起点的问
2017-08-23 17:01:14 1121
原创 leetcode(416). Partition Equal Subset Sum
problem Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal. Note: Each
2017-08-23 14:05:46 304
原创 leetcode(56). Merge Intervals
problem Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].solution# Definition for an interval.# c
2017-08-22 12:24:55 253
原创 leetcode(380). Insert Delete GetRandom O(1)
problem 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): Removes an i
2017-08-22 10:15:25 281
原创 HTML与css
什么是HTML超文本标记语言(英语:HyperText Markup Language,简称:HTML)是一种用于创建网页的标准标记语言。它负责网页的内容和结构,例如在一篇博客中可以用它来展示博客的内容以及标记博客的标题、正文等。后来为了更好的展示内容HTML中也加入了一些新的标签,例如font,i等,但是这与程序设计理念(单一职责原则)不符,这样导致的问题就是可读性降低(内容和格式混合到一起),维
2017-08-21 23:15:59 318
原创 leetcode(160). Intersection of Two Linked Lists
class Solution(object): def getIntersectionNode(self, headA, headB): """ :type head1, head1: ListNode :rtype: ListNode """ n1, n2 = 0, 0 a, b = headA
2017-08-19 15:05:25 226
原创 leetcode(206). Reverse Linked List
problem Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both? solution递归方法:#60%class Solution(object): def reverse
2017-08-19 11:24:51 236
原创 leetcode(538). Convert BST to Greater Tree
question Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key
2017-08-18 12:36:39 292
原创 leetcode(136). Single Number
problem Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it w
2017-08-17 21:51:46 214
原创 leetcode(394). Decode String
problem Given an encoded string, return it’s decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. No
2017-08-13 12:24:12 433
原创 leetcode(207). Course Schedule
problem There 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 i
2017-08-13 00:03:20 273
原创 leetcode(212). Word Search II
problem Design a data structure that supports the following two operations: void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containi
2017-08-12 10:39:15 299
原创 leetcode(208). Implement Trie (Prefix Tree)
problem Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z.solution本题中主要介绍了前缀树(trie)的定义及应用,详见solutionclas
2017-08-11 22:59:13 310
原创 leetcode(19). Remove Nth Node From End of List
problem Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node f
2017-08-11 20:11:34 175
原创 leetcode(139). Word Break
problem Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary word
2017-08-11 16:56:24 346
原创 leetcode(215). Kth Largest Element in an Array
problem Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k =
2017-08-11 14:56:43 312
原创 leetcode(169). Majority Element
problem 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 and the major
2017-08-10 23:12:15 220
原创 leetcode(283). Move Zeroes
problem 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, 12], after
2017-08-10 22:23:32 208
原创 leetcode(155). Min Stack
problem Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) – Push element x onto stack. pop() – Removes the element on top of the s
2017-08-10 21:11:17 258
原创 leetcode(448). Find All Numbers Disappeared in an Array
question Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in
2017-08-10 19:21:59 324
原创 leetcode(287). Find the Duplicate Number
problem Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one dupli
2017-08-10 16:20:00 256
原创 leetcode(221). Maximal Square
problem Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1
2017-08-10 08:53:39 273
原创 leetcode(152). Maximum Product Subarray
problem Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4], the contiguous subarray [2,3]
2017-08-08 13:32:39 308
原创 leetcode(560). Subarray Sum Equals K
problem Given 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: Th
2017-08-08 09:59:21 329
原创 leetcode(338). Counting Bits
problem Given 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. Exampl
2017-08-07 15:47:04 334
原创 leetcode(98). Validate Binary Search Tree
problem Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than t
2017-08-06 23:18:37 310
原创 leetcode(142). Linked List Cycle II
problem 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 ext
2017-08-06 21:25:53 250
原创 leetcode(78). Subsets
problem Given a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example, If nums = [1,2,3], a solution is: [
2017-08-06 14:33:57 243
原创 leetcode(62). Unique Paths
problem A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is try
2017-08-06 11:41:53 196
原创 leetcode(121). Best Time to Buy and Sell Stock
problem 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 one sha
2017-08-06 09:45:51 212
原创 leetcode(141). Linked List Cycle
problem Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?solution第一种解法不考虑使用额外空间,使用hash set判断是否出现重复的节点,判断是否有环。# Definition for singly
2017-08-05 18:12:05 386
原创 leetcode(55). Jump Game
problem 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 positio
2017-08-05 16:35:35 244
原创 leetcode(110). Balanced Binary Tree
problem Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every no
2017-08-04 22:48:58 251
原创 leetcode(102). Binary Tree Level Order Traversal
problem Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).分析题目要求对二叉树进行层次遍历,并且每一层的所有节点放在同一个list内输出,因此我的想法是按照普通的二叉树层次遍历只不过在每一层的结尾处
2017-08-04 12:49:39 247
原创 从python的列表推导式说起
引言之前在刷leetcode时用到了数组中元素都是0的情况,看到两种方式生成这样的list:[0]*n[0 for _ in range(n)]通过本地测试发现两种方式实现的效率并不一样,可偏偏这是一个二维dp问题,要生成一个二维数组,自然代码就要写成下面这样的形式了:[[0]*n]*m[[0 for _ in range(n)] for _ in range(m)]结果提交时就发现正确
2017-08-04 01:09:41 495
原创 leetcode(494). Target Sum
problem You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.
2017-08-03 22:26:57 338
原创 leetcode(543). Diameter of Binary Tree
problem Given 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 pa
2017-08-02 11:03:58 364
原创 leetcode(547). Friend Circles
problem 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 fri
2017-08-01 22:32:02 271
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人