![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 69
qbt4juik
这个作者很懒,什么都没留下…
展开
-
【Leetcode】Remove Element in JAVA
这个题目比较简单,所以就直接上答案啦。。。原创 2014-11-07 17:19:47 · 474 阅读 · 0 评论 -
【Leetcode】Length of Last Word JAVA
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-11-07 23:11:22 · 473 阅读 · 0 评论 -
【Leetcode】Valid Palindrome JAVA
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原创 2014-11-07 23:18:31 · 527 阅读 · 0 评论 -
【Leetcode】Integer To Roman in JAVA
这道题和之前的题目很像,需要将原创 2014-11-09 19:01:02 · 462 阅读 · 0 评论 -
【Leetcode】Roman to Integer JAVA
public class romanToInteger { public static void main(String args[]){ String s="XLIV"; romanToInteger rt = new romanToInteger(); System.out.println(rt.romanToInt(s)); } public int read(c原创 2014-11-08 20:48:20 · 502 阅读 · 0 评论 -
【Leetcode】three sum
鉴于刚刚写了两个blog莫名其妙被CSDN吞了很不爽原创 2014-11-09 01:54:52 · 445 阅读 · 0 评论 -
【Leetcode】String to Integer(atoi) in JAVA
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2014-11-09 19:11:18 · 519 阅读 · 0 评论 -
【Leetcode】Word Break JAVA
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"原创 2014-11-09 00:50:12 · 518 阅读 · 0 评论 -
【Leetcode】zigzagConversion JAVA
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2014-11-09 20:37:18 · 419 阅读 · 0 评论 -
【Leetcode】Surrounded Region in JAVA
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 X原创 2014-11-10 18:42:40 · 413 阅读 · 0 评论 -
【Leetcode】Valid Sudoku in JAVA
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 fille原创 2014-11-10 20:16:01 · 453 阅读 · 0 评论 -
【Leetcode】Best Time to Buy and Sell Stock II in JAVA
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-11-12 00:29:42 · 453 阅读 · 0 评论 -
【Leetcode】Unique Binary Search Tree in JAVA
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 \原创 2014-11-11 23:39:57 · 389 阅读 · 0 评论 -
【Leetcode】Binary Tree Inorder Traversal in JAVA
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-11-12 22:48:55 · 386 阅读 · 0 评论 -
【Leetcode】Merge Sorted Array in JAVA
哼。。这么简单还一次没过,气死我了……Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold原创 2014-11-13 00:01:32 · 359 阅读 · 0 评论 -
【Leetcode】Maximum Subarray in JAVA
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1]原创 2014-11-15 00:06:15 · 401 阅读 · 0 评论 -
【Leetcode】Populating Next Right Pointers in Each Node in JAVA
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2014-11-15 00:18:29 · 394 阅读 · 0 评论 -
【Leetcode】Binary Tree Preorder Traversal in JAVA
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti原创 2014-11-13 22:15:50 · 341 阅读 · 0 评论 -
【Leetcode】Valid Parentheses in JAVA——一个括号de了20分钟bug的故事
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-11-13 23:27:17 · 600 阅读 · 0 评论 -
【Leetcode】Jump Game in JAVA
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2014-11-15 23:36:37 · 394 阅读 · 0 评论 -
【Leetcode】Search Insert Position in JAVA
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-11-16 00:53:08 · 533 阅读 · 0 评论 -
【Leetcode】Remove Duplicates from Sorted List in JAVA
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.思路很简单,由于乖乖的sort好了,就是判断下原创 2014-11-19 16:02:44 · 624 阅读 · 0 评论 -
【Leetcode】经典的Jump Game in JAVA
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2014-11-19 16:08:28 · 779 阅读 · 0 评论 -
【Leetcode】Reverse Linked List II in JAVA
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the原创 2014-11-20 22:18:09 · 542 阅读 · 0 评论 -
【Leetcode】Merge Two Sorted Lists in JAVA
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.public class mergeTwoSortedList { public static v原创 2014-11-20 22:24:51 · 445 阅读 · 0 评论 -
【Leetcode】Remove Duplicates from Sorted Array in JAVA
import java.util.Arrays;import java.util.HashMap;import java.util.Iterator;import java.util.Map;public class removeDupFromSortedArray { public static void main(String args[]){ removeDupFromSor原创 2014-11-22 22:25:38 · 390 阅读 · 0 评论 -
【Leetcode】Convert Sorted Array to Binary Search Tree in JAVA
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.原创 2014-11-22 22:33:37 · 419 阅读 · 0 评论 -
【Leetcode】Intersection of Two Linked Lists in JAVA
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2014-11-27 23:01:38 · 1000 阅读 · 0 评论 -
【Leetcode】Unique Paths in JAVA
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原创 2014-11-27 10:15:26 · 626 阅读 · 0 评论 -
【Leetcode】Swap Nodes in Pairs in JAVA 难得的一次写对不带改的。。附赠测试程序like always
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-11-23 23:22:14 · 712 阅读 · 0 评论 -
【Leetcode】Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",原创 2014-11-27 10:54:54 · 588 阅读 · 0 评论 -
【Leetcode】Generate Parentheses in JAVA
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-11-29 09:13:04 · 637 阅读 · 0 评论 -
【Leetcode】Container With Most Water in JAVA
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原创 2014-11-29 09:15:30 · 609 阅读 · 0 评论 -
【Leetcode】Reverse Words in a String JAVA
Reverse Words in a StringGiven an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".原创 2014-11-06 21:21:59 · 545 阅读 · 0 评论 -
【Leetcode】Add two numbers JAVA
import testAndfun.LLCycle.ListNode;public class addTwoNum {public staticvoid main(String[] args) { ListNode l1 = new ListNode(2); ListNode x2 = new ListNode(4); Li原创 2014-11-05 22:25:56 · 601 阅读 · 0 评论 -
【Leetcode】Sort List in java,你绝对想不到我是怎么做的^^我写完过了我自己都觉得好jian~
Sort a linked list in O(n log n) time using constant space complexity.大家看完题目估计跟我一样啦。。。都在想哪些是nlogn啊~快速排序、归并排序、堆排序!然后开始愁,这些东西变成list了可怎么办啊。。。可是我深深地记得在CMU的时候老师告诉我,java现在自带的Arrays.sort用的是快排,然后我就想,那么…原创 2014-11-23 23:54:04 · 892 阅读 · 1 评论 -
【Leetcode】Search a 2D Matrix in JAVA
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each原创 2014-11-29 16:07:22 · 615 阅读 · 0 评论 -
【Leetcode】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?这个问题也比较简单,我就直接贴出jie原创 2014-11-06 21:32:48 · 394 阅读 · 0 评论 -
【Leetcode】two sum JAVA
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-11-07 23:21:15 · 515 阅读 · 0 评论 -
【Leetcode】Climbing Stairs JAVA
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?见到这种题目,第一个x原创 2014-11-07 21:02:37 · 448 阅读 · 0 评论