- 博客(66)
- 资源 (1)
- 问答 (3)
- 收藏
- 关注
原创 LeetCode Delete Node in a Linked List
Description:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the thi
2015-07-15 18:02:09 496
原创 LeetCode Lowest Common Ancestor of a Binary Search Tree
Description:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancest
2015-07-15 17:03:21 382
原创 LeetCode Palindrome Linked List
Description:Given a singly linked list, determine if it is a palindrome.Solution:先将整个链表反转,然后正反两个链表同时遍历,对比相应的valimport java.util.*;public class Solution { public boolean isPalindrome(List
2015-07-15 15:27:31 568
原创 LeetCode Implement Queue using Stacks
Description:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the fr
2015-07-11 22:53:05 314
原创 LeetCode Power of Two
Description:Given an integer, write a function to determine if it is a power of two.Solution:如果小于等于0,则不可能如果大于0,则求出他的二进制中,是否只有一个1import java.util.*;public class Solution { public boolean
2015-07-11 22:46:40 290
原创 LeetCode Kth Smallest Element in a BST
Description:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Solution:类似于平衡树的做法,只不过每个节点没有保存有多少个左右子节点,而是在线计算。设当前节点的左子树有left个子节点1. left + 1
2015-07-11 22:43:51 220
原创 LeetCode Majority Element II
Description:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.Solution:空间复杂度都要O(1),着实捉急了一下
2015-07-11 11:50:50 295
原创 LeetCode Summary Ranges
Description:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].Solution:题意略微有点难懂,就是将数组进行分段,每一段
2015-07-11 11:10:12 235
原创 LeetCode Invert Binary Tree
Description:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Solution:DFS递归可以解决import java.util.*;public class
2015-07-11 09:28:36 253
原创 LeetCode Implement Stack using Queues
Description: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.empt
2015-07-11 09:22:14 242
原创 Basic Calculator & Basic Calculator II
Basic CalculatorDescription:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus
2015-07-11 08:59:28 385
原创 LeetCode Rectangle Area
Description:Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.As
2015-07-10 11:17:35 238
原创 LeetCode Count Complete Tree Nodes
Description:Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is
2015-07-10 11:16:01 273
原创 LeetCode Maximal Square
Description:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1
2015-07-09 21:33:44 263
原创 LeetCode Contains Duplicate III
Description:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference
2015-07-09 19:46:24 276
原创 LeetCode Contains Duplicate II
Description:Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand
2015-07-09 17:04:36 344
原创 LeetCode Combination Sum III
Description:Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.En
2015-07-09 16:42:16 386
原创 LeetCode Kth Largest Element in an Array
Description:Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.En
2015-07-09 15:50:53 252
原创 LeetCode House Robber II
Description:Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much at
2015-07-09 14:52:11 205
原创 LeetCode Course Schedule II
Description: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, whic
2015-07-09 14:10:16 253
原创 LeetCode Implement Trie (Prefix Tree)
Description:Implement a trie with insert, search, and startsWith methods.Solution:Trie树是字符串常用的一个数据结构,AC自动机也会用到。这里需要注意的是,prefix和search功能的不一样,也就要求了要在每个节点中添加一个标记,记录当前节点是否表示一个字符串的结束。public cla
2015-07-09 10:53:11 179
原创 LeetCode Course Schedule
Description:here 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
2015-07-09 10:16:10 176
原创 LeetCode Reverse Linked List
Description:Reverse a singly linked list.Solution:正着读一遍,然后类似入栈即可。import java.util.*;public class Solution { public ListNode reverseList(ListNode head) { ListNode tail = null; ListNod
2015-07-09 10:01:44 241
原创 LeetCode Isomorphic Strings
Description:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be
2015-07-09 00:59:35 251
原创 LeetCode Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.Solution:可以用筛法求素数。先用2把所有2的倍数去掉,3把所3的倍数去掉,依此类推。这道题目出的不是特别好,因为n如果太大,筛法也是不可行的,首先数组就没办法开那么大。import java.uti
2015-07-09 00:46:33 165
原创 LeetCode Remove Linked List Elements
Description:Remove all elements from a linked list of integers that have value val.Solution:需要单独考虑链表头。import java.util.*;public class Solution { public ListNode removeElements(ListNode he
2015-07-09 00:40:08 242
原创 LeetCode Happy Number
Description:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the
2015-07-09 00:35:38 206
原创 LeetCode Number of Islands
Description:Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertic
2015-07-09 00:24:30 285
原创 LeetCode Binary Tree Right Side View
Description:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following bi
2015-07-08 21:31:56 231
原创 LeetCode House Robber
Description:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is tha
2015-07-08 21:09:55 258
原创 LeetCode Number of 1 Bits
Description:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary rep
2015-07-08 21:02:58 231
原创 LeetCode Reverse Bits
Description:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in b
2015-07-08 21:00:37 323
原创 LeetCode Rotate Array
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 as ma
2015-07-08 20:22:18 210
原创 LeetCode Repeated DNA Sequences
Description:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences with
2015-07-08 18:16:19 282
原创 LeetCode Valid Palindrome
Description:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."rac
2015-07-08 08:57:36 221
原创 LeetCode Best Time to Buy and Sell Stock III
Description:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.
2015-07-08 08:26:33 249
原创 LeetCode Best Time to Buy and Sell Stock II
Description:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as yo
2015-07-07 16:25:15 254
原创 LeetCode Best Time to Buy and Sell Stock
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 one sh
2015-07-07 14:36:47 190
原创 LeetCode Triangle
Description:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2
2015-07-07 14:33:00 192
原创 LeetCode Pascal's Triangle II
Description:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Solution:和Pascal's Triangle没区别。import java.util.*;public class S
2015-07-07 14:20:49 255
java中的sql语句为何会报错,而到了workbench就可以执行
2015-03-17
Python获得网卡IP的几个参数问题
2015-01-12
Python中注释前面加上引号是什么意思?
2014-12-30
TA创建的收藏夹 TA关注的收藏夹
TA关注的人