![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
xtrb
这个作者很懒,什么都没留下…
展开
-
Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings.自己开始写的,真得好挫啊。。。思路是逐个增加最长公共前缀的长度,加入的条件是对当前的下标值,所有字符串数组中的字符串的值都一样,否则返回得到的最长公共前缀。public static String long原创 2015-12-10 10:33:07 · 395 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is原创 2015-11-30 18:01:02 · 345 阅读 · 0 评论 -
Remove Element
题目:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new lengt原创 2015-12-16 23:37:01 · 289 阅读 · 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.思路:原创 2015-12-31 19:59:09 · 374 阅读 · 0 评论 -
Implement strStr()
题目: Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.思路:直接暴力掉了。。 public class Solution { public int str...原创 2015-12-17 17:19:42 · 334 阅读 · 0 评论 -
ZigZag Conversion
题目: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原创 2015-12-01 20:40:51 · 333 阅读 · 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 ...原创 2015-12-19 22:12:10 · 347 阅读 · 0 评论 -
Reverse Integer
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321唯一要注意的点就是溢出。public class Solution { public int reverse(int x) { long num = 0;原创 2015-12-02 23:11:25 · 288 阅读 · 0 评论 -
Palindrome Number
题目:Determine whether an integer is a palindrome. Do this without extra space.解法一:把整数变成字符串,然后用判断回文串的方法进行判断。public class Solution { public boolean isPalindrome(int x) { if (x < 0)原创 2015-12-06 19:31:39 · 306 阅读 · 0 评论 -
Add Binary
题目: Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".思路:两个二进制位和进位相加的的结果有4种(0,1,2,3),所以只要两个字符串都逐位从最后一位往前遍历,并用一个变量保存进位,然后对三者相加结果进行相应...原创 2015-12-27 13:25:53 · 553 阅读 · 0 评论 -
Plus One
题目: Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.思路:因为就加一个数1,所以...原创 2015-12-26 23:46:36 · 384 阅读 · 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原创 2015-11-29 15:40:10 · 376 阅读 · 0 评论 -
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原创 2015-11-28 20:38:31 · 377 阅读 · 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原创 2015-12-11 01:02:43 · 373 阅读 · 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.思路:太简单了,直接看代码吧。。/** * Definition for singly原创 2015-12-12 22:24:20 · 407 阅读 · 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原创 2015-12-12 00:18:47 · 326 阅读 · 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个阶...原创 2015-12-28 00:14:26 · 417 阅读 · 0 评论 -
Combine Two Tables
题目:Table: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+-----原创 2015-12-13 20:59:41 · 563 阅读 · 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 ta原创 2015-11-26 11:16:15 · 560 阅读 · 0 评论 -
House Robberm
题目:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjac原创 2015-12-14 00:14:27 · 284 阅读 · 0 评论 -
Happy Number
题目:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of th原创 2015-12-14 21:28:57 · 361 阅读 · 0 评论 -
Merge Sorted Array
题目:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to h原创 2015-12-30 00:05:30 · 468 阅读 · 0 评论 -
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 p原创 2015-12-15 22:14:40 · 296 阅读 · 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...原创 2015-12-28 18:45:27 · 508 阅读 · 0 评论