- 博客(22)
- 收藏
- 关注
原创 (java)leetcode Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.思路1:本题是要找一个字符串数组的最长公共前缀。首先求出最短字符串的长度,然后从0到最短字符串长度遍历每个字符串,找到最长的公共前缀代码如下(已通过leetcode)public class Solution {
2015-10-30 18:47:02 334
原创 (java)leetcode Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...
2015-10-30 18:42:10 331
原创 (java)leetcode Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element
2015-10-30 18:31:11 340
原创 (java)leetcode Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howe
2015-10-30 18:24:38 359
原创 (java)leetcode Move Zeros
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-29 19:11:29 610
原创 (java)leetcode 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-10-29 19:06:19 270
原创 (java)leetcode Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with val
2015-10-29 18:59:30 277
原创 (java)leetcode 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.思路:本题就是最简单的树的遍历题,DFS和BFS都可以,我是采用的B
2015-10-29 18:52:36 277
原创 (java) leetcode Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on
2015-10-29 17:04:28 472
原创 (java)leetcode problem192 Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the
2015-10-29 16:57:53 440
原创 leetcode problem13 Rome to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路:从前向后遍历这个字符串如果当前值等于前一个值 则用一个临时变量存储当前的值 如III=3;如果当前值比前一个值大 则这个临时变量存储的值应该为当前值减
2015-10-28 17:12:00 308
原创 leetcode Problem12 Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思路:首先先把num按照个位十位百位千位拆分,然后对每一位上的数字按照roman to integer的对应表格,转化为对应的roman,然后就所有转化的再拼起来就是所求的
2015-10-28 17:06:40 306
原创 LeetCode Problem10 Regular Expression Matching
'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The function prototype should be:bool isMatch(c
2015-10-26 17:30:04 530
原创 LeetCode Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.思路:就是简单的判断是不是回文数,在头尾设置两个指针i和j,判断是不是一直相等就行。本题的关键是不要有额外的空间,所以创建一个数组就是不可行的了,我是将其转换成了字符串。代码如下,已通过(leetcode)扯淡几句:由于在机房没带耳机,没法学别
2015-10-24 19:49:38 325
原创 leetcode Problem8_StringtoInt
Implement atoi to convert a string to an integer.思路:本题的题目本身比较简单,但是case非常的多比如:1 "+"2 " +-12"3 " 0012a45"4 溢出等等,本题的重点就在于处理这些case。下面代码(已经通过lootcode)今天就刷到这,保持基本每天4题的速度public class
2015-10-24 17:56:20 369
原创 leetcode problem7 Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321思路:题目本身简单的不能再简单了,但是其中有一个边界问题,也是这个题目存在的道理,就是当输出的整数没有越界,而转置之后的整数可能会越界。比如 1534236469本身并没有越界,而转置之后就96463243
2015-10-24 16:45:54 437
原创 LeetCode Problem6 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 P L S I
2015-10-24 16:16:59 350
原创 LeetCode Problem5 LongestPalindromicSubstring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.思路:1 本题有两种想法,第一种是找
2015-10-24 15:42:40 363
原创 Leetcode Problem4 Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).思路1:本题毫无疑问第一反应肯定是使用递归求解。此
2015-10-23 17:10:32 337
原创 Leetcood Problem3 longest substring
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 3. Fo
2015-10-23 15:51:08 538
原创 Leetcode Problem2 two numbers
Add Two NumbersYou 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 num
2015-10-23 14:02:37 391
原创 leetcode Problem1 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
2015-10-22 23:28:30 468
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人