leetcode
tingting256
这个作者很懒,什么都没留下…
展开
-
leetcode:397. Integer Replacement 详细分析及源代码
位操作这一块不熟,所以特意去leetcode上找题看了一下。 题目如下: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 +原创 2016-09-17 00:41:13 · 638 阅读 · 0 评论 -
leetcode 233: Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the follow转载 2015-10-29 16:17:11 · 406 阅读 · 0 评论 -
leetcode:Copy List with Random Pointer 细致分析,以及代码实现(JAVA版本)
深度复制链表 java实现原创 2015-10-29 15:20:35 · 382 阅读 · 0 评论 -
leetcode 68:Text Justification细致分析,java实现
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i原创 2015-11-12 20:49:58 · 821 阅读 · 0 评论 -
leetcode 241:Different Ways to Add Parentheses
递归计算字符串算术表达式原创 2015-09-24 14:36:58 · 592 阅读 · 0 评论 -
leetcode:Kth Largest Element in an Array 使用快速选择算法,以及对其复杂度的分析
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 = 2, return 5原创 2015-09-23 14:56:24 · 1128 阅读 · 0 评论 -
leetcode279:Perfect Squares
使用动态规划解决离散背包问题原创 2015-09-22 15:33:49 · 452 阅读 · 0 评论 -
leetcode 23:Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目分析:两个链表的链接会不会,归并排序,复杂度为O(N),N为节点数。多个链表排序,两个两个归并,再归并,这样相当于做了logK层,每一层都为N,则复发度为o(NlogK),public原创 2015-10-25 21:23:01 · 283 阅读 · 0 评论 -
leetcode:ExpressionAddOperators282 细致讲解 以及代码实现
Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value.原创 2015-10-24 14:27:19 · 1198 阅读 · 0 评论 -
leetcode:Reverse Linked List
题目分析:把链表反过来,找一个list存链表,逆序遍历建立关系即可。具体代码如下:public ListNode reverseList(ListNode head) { if(head==null) return null; List list=new ArrayList(); ListNode p=head; //存储链表 while(p!=null)原创 2015-09-20 22:33:31 · 288 阅读 · 0 评论 -
leetcode 287:Find the Duplicate Number 二分法查找 java版
二分法查找重复数原创 2015-10-29 17:14:12 · 863 阅读 · 0 评论 -
leetcode 29:Divide Two Integers
leetcode 29:Divide Two Integers java源码实现原创 2015-10-15 22:33:15 · 338 阅读 · 0 评论 -
leetcode 218. The Skyline Problem 使用PriorityQueue的java实现 以及细致分析
题目解析:要得到大致轮廓,我们首先可以将X轴排序,高度为正插入,高度为负,删除对应高度。每次取得一个高度应该是所有高度中最高的,想到使用PriorityQueue。每次插入或删除,需要比较当前高度与之前最高值的大小,不一样就更新结果集。public List getSkyline(int[][] bs) { List res=new ArrayList();原创 2015-12-28 15:13:44 · 833 阅读 · 0 评论 -
leetcode 109. Convert Sorted List to Binary Search Tree 源代码加详细思路和注释
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Subscribe to see which companies asked this question题目分析:将排好序的链表转换成平衡二叉树。我们想一下怎么将原创 2016-05-09 11:21:10 · 362 阅读 · 0 评论 -
leetcode 205. Isomorphic Strings 巧妙使用hashmap.put返回值求解
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 replaced with anot原创 2016-05-10 22:22:52 · 321 阅读 · 0 评论 -
leetcode 140:Word Break II 采用很巧妙的动态规划和DFS联合使用 JAVA源代码实现
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "原创 2015-12-22 19:20:21 · 2081 阅读 · 0 评论 -
leetcode 212: Word Search II使用前缀树,java实现
利用前缀树的DFS字符串搜索原创 2015-12-21 22:06:23 · 1210 阅读 · 0 评论 -
java 前缀树实现 leetcode 208: Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.1.前缀树的概念所有含有公共前缀的字符串将挂在树中同一个结点下。实际上trie简明的存储了存在于串集合中的所有公共前缀。2.举例说明假如有这样一个字符串集合X{bear,bell,bid,bull,buy,sell,stock,stop}。它的标准Tri原创 2015-12-21 20:54:11 · 1926 阅读 · 0 评论 -
leetcode126:Word Ladder II 详细结题报告 以及java实现源代码
leetcode126:Word Ladder II 详细结题报告 以及java实现源代码。首先建立反向链接表,之后通过DFS求解。转载 2015-12-20 19:55:14 · 1169 阅读 · 0 评论 -
leetcode 214:Shortest Palindrome 题目分析 与使用KMP算法的java实现
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For exam原创 2016-01-04 11:21:55 · 1651 阅读 · 1 评论 -
leetcode 5:Longest Palindromic Substring 三种解法的java实现源代码,以及详细讲解
题目分析:查找一个字符串中中最长回文字符串1.算法1:暴力检索 既然要查最长的回文字符串,那么直接对每一个字符,以它为中心,找到最长的回文字符串,更新最大值最小值就行了。注意要分两种情况,1/**对每一个字母,都查找最大的回文串的长度,left,right分别表示回文串的起始位置*/ public String longestPalindrome(String s) { int原创 2016-01-02 23:51:35 · 1606 阅读 · 0 评论 -
leetcode316: Remove Duplicate Letters 使用递归的简单java实现
Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order a原创 2015-12-28 22:58:08 · 1754 阅读 · 0 评论 -
leetcode 295:Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median原创 2015-10-23 17:13:29 · 369 阅读 · 0 评论 -
leetcode 238:Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O转载 2015-09-18 14:18:59 · 276 阅读 · 0 评论 -
leetcode:Lowest Common Ancestor of a Binary Search Tree
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 ancestor is defined betwee原创 2015-09-18 10:42:25 · 300 阅读 · 0 评论 -
leetcode:Longest Valid Parentheses 使用动态规划O(n)思路
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",原创 2015-09-27 17:08:29 · 935 阅读 · 0 评论 -
leetcode:Minimum Window Substring 细致分析
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN原创 2015-09-10 15:12:31 · 447 阅读 · 0 评论 -
leetcode:Basic Calculator II
leetcode 简易计算器的实现原创 2015-09-09 21:01:46 · 279 阅读 · 0 评论 -
leetcode 222:Count Complete Tree Nodes
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 completely fille原创 2015-09-26 23:12:55 · 362 阅读 · 0 评论 -
leetcode:ugly Number II
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原创 2015-09-08 14:55:26 · 253 阅读 · 0 评论 -
leetcode 239:Sliding Window Maximum
使用linkedList快速地获得一定窗口中的最大元素原创 2015-09-26 11:30:41 · 486 阅读 · 0 评论 -
leetcode:Sort List 使用归并排序的解决思路
使用归并排序对链表进行排序原创 2015-09-26 09:55:40 · 645 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
递归求解二叉树的最大路径问题原创 2015-09-26 15:51:35 · 359 阅读 · 0 评论 -
leetcode 229:Majority Element II
根据摩尔投票解决majority问题原创 2015-09-25 15:48:55 · 584 阅读 · 0 评论 -
leetcode:Interleaving String 使用动态规划求解的java源代码
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", r原创 2015-09-28 14:24:12 · 496 阅读 · 0 评论 -
leetcode:Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in wordsexactly once and w原创 2015-09-07 15:37:39 · 435 阅读 · 0 评论 -
leetcode:TwoSum
Leetcode 对于TwoSun题目的分析,以及用hashmap巧妙求解,代码为java实现原创 2015-09-12 20:32:46 · 316 阅读 · 0 评论 -
leetcode:Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t转载 2015-09-17 17:35:58 · 424 阅读 · 0 评论 -
leetcode:151Reverse Words in a String java实现
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".题目分析:太简单了,要注意一点 split可能会返回空串 public String reverseWords(String s) {原创 2015-09-17 19:15:57 · 477 阅读 · 0 评论 -
leetcode130:Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O XX X原创 2015-09-17 20:29:46 · 299 阅读 · 0 评论