
leetcode-java
文章平均质量分 58
ohyeslk
这个作者很懒,什么都没留下…
展开
-
Remove Nth Node From End of List
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 from the end, the原创 2014-07-14 22:34:48 · 249 阅读 · 0 评论 -
Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.罗马数字转整数 = =原创 2014-07-17 23:18:43 · 233 阅读 · 0 评论 -
Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-原创 2014-07-20 09:55:41 · 317 阅读 · 0 评论 -
Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio原创 2014-07-20 09:32:54 · 243 阅读 · 0 评论 -
Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-07-20 09:32:50 · 281 阅读 · 0 评论 -
Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?原创 2014-07-20 09:47:05 · 261 阅读 · 0 评论 -
Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2014-07-20 10:01:29 · 210 阅读 · 0 评论 -
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.1.递归原创 2014-07-20 09:58:27 · 238 阅读 · 0 评论 -
Remove Nth Node From End of List
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 from the end, the原创 2014-07-20 10:06:34 · 323 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3删除链表中的重复点原创 2014-07-20 09:53:28 · 248 阅读 · 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?原创 2014-07-20 09:47:10 · 268 阅读 · 0 评论 -
N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.经典的八皇后问题这个比n皇后1简单 先做这个。规则是 行、列、正反对角线上都只能有一个皇后。1.常规做法。 递归原创 2014-07-22 17:42:47 · 246 阅读 · 0 评论 -
Insertion Sort List
Sort a linked list using insertion sort.用插入排序来排链表/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val原创 2014-07-23 17:54:10 · 236 阅读 · 0 评论 -
Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition for binary tree原创 2014-08-01 11:02:25 · 261 阅读 · 0 评论 -
Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2014-10-31 07:21:03 · 267 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III
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.Note:You may原创 2014-07-19 00:28:52 · 252 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
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 share of the stock),原创 2014-07-19 00:20:41 · 261 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100"1.sum的数组长度不可以定义,否则没有进位的数最前面会有一个空格2.Char和string的转换3.进位表示法原创 2014-07-18 23:57:52 · 259 阅读 · 0 评论 -
Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You m原创 2014-07-14 21:53:02 · 327 阅读 · 0 评论 -
Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2014-07-17 17:16:19 · 236 阅读 · 0 评论 -
Pow(x, n)
Implement pow(x, n).最先想到的就是d原创 2014-07-17 11:19:36 · 272 阅读 · 0 评论 -
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.原创 2014-07-17 23:07:38 · 242 阅读 · 0 评论 -
4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element原创 2014-07-18 23:53:02 · 228 阅读 · 0 评论 -
Balanced Binary Tree
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 node never diffe原创 2014-07-19 00:00:35 · 272 阅读 · 0 评论 -
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层楼梯 每次能走1huo原创 2014-07-18 20:31:45 · 258 阅读 · 0 评论 -
Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2014-07-18 23:36:46 · 229 阅读 · 0 评论 -
Best Time to Buy and Sell Stock II
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 you like (ie, buy on原创 2014-07-19 00:20:07 · 243 阅读 · 0 评论 -
Copy List with Random Pointer
Copy List with Random Pointer Total Accepted: 14031 Total Submissions: 61754My SubmissionsA linked list is given such that each node contains an additional random pointer which could poi原创 2014-07-15 17:55:07 · 598 阅读 · 0 评论 -
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 extra原创 2014-07-18 23:31:39 · 308 阅读 · 0 评论 -
Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.原创 2014-07-18 23:36:52 · 337 阅读 · 0 评论 -
3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly原创 2014-07-18 23:53:11 · 237 阅读 · 0 评论 -
Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2014-07-18 23:28:06 · 236 阅读 · 0 评论 -
Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before coding.原创 2014-07-18 23:42:46 · 243 阅读 · 0 评论 -
3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:· Elements in a triplet (a,b,c) must原创 2014-07-18 23:48:17 · 227 阅读 · 0 评论