- 浏览: 201165 次
- 性别:
- 来自: 杭州
最新评论
-
hthhit:
...
回溯算法之N皇后问题(java实现) -
huntfor:
249326109 写道这个算法的复杂度有考虑过么O(n^2) ...
[leetcode]Longest Valid Parentheses -
249326109:
这个算法的复杂度有考虑过么
[leetcode]Longest Valid Parentheses -
huntfor:
249326109 写道又搜到你的了 你怎么搜的,为啥我搜不到 ...
[leetcode]Sort Colors -
249326109:
又搜到你的了
[leetcode]Sort Colors
文章列表
新博文跟本文算法一样,为了习惯 -> 新博文地址:[leetcode]Valid Sudoku
Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially filled sudoku which is valid.Note:A valid Sudoku boa ...
新博文地址:[leetcode]Recover Binary Search Tree
Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?
这道题想复杂 ...
(这道题还是不要看这篇旧博文比较好)新博文地址:[leetcode]Text Justification
Text Justification
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 is, pack as many words as you ...
新博文地址:[leetcode]Restore IP Addresses
Restore IP Addresses
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 doe ...
新博文地址:[leetcode]Unique Binary Search Trees II
Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ ...
第二遍的做法居然跟第一遍完全一样:
新博文地址:[leetcode]Word Search
Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally ...
LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value) - Set or insert the value i ...
事实证明,是时间而不是tolowcase的问题。新博文地址:[leetcode]Valid Palindrome
Valid Palindrome
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."race a car" is not a palindrome. ...
新博文地址:
[leetcode]Reverse Nodes in k-Group
Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.You may not alter the valu ...
新博文地址:[leetcode]Sort List
Sort List
Sort a linked list in O(n log n) time using constant space complexity.
题中要求以O(n log n)的时间复杂度完成排序,并且只能开常数个空间。一般而言,满足O(n log n)的条件,第一直觉就是快排和归并,但是鉴于快排要往前迭代,但是题中要求是单链表,因此选择归并排序。
至于归并排序的就不多说了,具体的做法是用递归实现
1. 将链表一分为二(找中点方法有二: 1. 计算中间节点的index(list.size/2) ...
(本博文作废,算法太挫,新博文将代码压缩至一半以下,可读性也更好)
新博文地址:[leetcode]Search for a Range
Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found in the array, re ...
新博文地方:[leetcode]Spiral Matrix II
Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]
好在这道题是n * n矩阵,如果是m * n就复杂了。
女朋友不是计算机专业,只会 ...
新博文地址:[leetcode]Insertion Sort List
Insertion Sort List
Sort a linked list using insertion sort.
用插入排序,对一个单链表进行排序。
插入排序就不多讲了,单链表还是数组,道理都是一样的,只不过单链表略微麻烦一点,好在算法比较简单,难度不大。
public ListNode insertionSortList(ListNode head) {
if(head == null || head.next == null){
return head; ...
新博文地址:[leetcode]Trapping Rain Water
Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.[picture]The above elevation map is ...
新博文地址:[leetcode]Convert Sorted List to Binary Search Tree
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.
跟这道题很相似,没道理没写博文啊(= =//)算了,反 ...