Leetcode
文章平均质量分 64
Javasus
自信人生二百年,会当水击三千里。
展开
-
Remove Duplicates from Sorted Array
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 must do this in place with原创 2015-03-15 01:51:18 · 525 阅读 · 0 评论 -
[DP] Unique Paths
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 trying to reach the原创 2015-12-10 14:51:20 · 943 阅读 · 0 评论 -
Find Peak Element
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 contain multiple peaks, i原创 2015-11-23 19:19:08 · 503 阅读 · 0 评论 -
Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Floyd判圈算法的典型应用场景①使用Floyd判圈算法直接求解/** * Definition for singly-linked list.原创 2015-11-25 11:11:27 · 1031 阅读 · 0 评论 -
Floyd判圈算法理解
关于该算法,wiki上有详细说明。https://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_harehttps://zh.wikipedia.org/wiki/Floyd%E5%88%A4%E5%9C%88%E7%AE%97%E6%B3%95Floyd判圈算法(Floyd Cycle Detection Algorit原创 2015-11-24 18:16:24 · 6218 阅读 · 4 评论 -
[DP] Minimum Path Sum
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 move either down or right at原创 2015-12-14 14:56:34 · 563 阅读 · 0 评论 -
[Binary Search]Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2015-12-16 16:32:45 · 470 阅读 · 0 评论 -
[Leetcode] Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first fi原创 2015-11-30 14:45:34 · 430 阅读 · 0 评论 -
[Leetcode]Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2015-10-19 16:32:26 · 1186 阅读 · 0 评论 -
Pow(x, n)
Implement pow(x, n).public class Solution { double myPow(double x, int n) { if(n==0) return 1; if(n<0){ n = -n; x = 1/x; } return n%2==0原创 2015-12-07 15:02:16 · 428 阅读 · 0 评论 -
[Merge Sort] Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.一、比较排序/** * Definition for singly-linked list. *原创 2015-10-22 11:04:32 · 479 阅读 · 0 评论 -
[Leetcode]Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Credits:Special than原创 2015-10-12 14:46:23 · 1973 阅读 · 0 评论 -
Insertion Sort List
Sort a linked list using insertion sort.分析:插入排序处理链表。借助一个helper 头节点,来避免比较过程中位置在头节点处的情况。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next;原创 2015-10-26 17:19:18 · 456 阅读 · 0 评论 -
[Leetcode] Number of 1 Bits
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 representation 000000原创 2015-03-22 02:13:41 · 939 阅读 · 1 评论 -
[Leetcode] Single Number
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 without using e原创 2015-03-22 02:36:27 · 401 阅读 · 0 评论 -
[Leetcode]Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2015-10-16 17:33:42 · 381 阅读 · 0 评论 -
[Leetcode] Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.方法一:假设链表长度为N,倒数第k处节点,对应正数第N+1原创 2015-11-03 15:50:14 · 1014 阅读 · 0 评论 -
[Leetcode] 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 or vertically原创 2015-10-21 16:11:28 · 1041 阅读 · 0 评论 -
[Leetcode] Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?题意:台阶总数为n,每次爬1阶或者2阶层,求爬完台阶原创 2015-10-21 18:49:10 · 1053 阅读 · 0 评论 -
[Leetcode] Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may a原创 2015-10-21 17:46:03 · 449 阅读 · 0 评论 -
[Leetcode]Move Zeroes
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 calling you原创 2015-10-10 12:51:18 · 3415 阅读 · 0 评论 -
[leetcode] Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?分析:palindrome:回文字,左后看都是一样。O(1)常数运行空间,说明不能通过建立数组等其他数据结构的方式来处理。从左右看,都是一样,考原创 2015-10-23 18:12:38 · 367 阅读 · 0 评论 -
[Leetcode] 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-11-11 16:40:19 · 401 阅读 · 0 评论 -
[DP] Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2015-12-07 14:24:43 · 656 阅读 · 0 评论