LeetCode
文章平均质量分 75
Yellow5A5
more and more!
展开
-
LeetCode-9 Palindrome Number(判断是否为回文int型)
LeetCode-9 Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. 方法一:直接转String倒置public class Solution { public boolean isPalindrome(int x) {原创 2015-04-18 09:28:24 · 1111 阅读 · 0 评论 -
LeetCode-24 Swap Nodes in Pairs(链表中按要求交换节点)
LeetCode-24 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原创 2015-04-29 17:12:57 · 491 阅读 · 0 评论 -
LeetCode-22 Generate Parentheses(合法括号情况)
LeetCode-22 Generate Parentheses(合法括号情况) 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:"(((原创 2015-04-29 17:01:18 · 611 阅读 · 0 评论 -
LeetCode-27 Remove Element(水题-去掉元素)
LeetCode-27 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 yo原创 2015-04-29 17:34:59 · 574 阅读 · 0 评论 -
LeetCode-28 Implement strStr() (找出字串位置)
LeetCode-28 Implement strStr() (找出字串位置)Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signa原创 2015-04-29 17:49:19 · 500 阅读 · 0 评论 -
LeetCode-49 Anagrams(返回字符相同的字符串)
LeetCode-49 Anagrams(返回字符相同的字符串)Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case. 一开始理解错题意。WA了好多次。。题目是指 返回字符串数组内 所有组成字符均相同的字符串原创 2015-04-29 18:07:40 · 810 阅读 · 0 评论 -
LeetCode-73 Set Matrix Zeroes(设置零矩阵)
LeetCode-73 Set Matrix Zeroes(设置零矩阵)Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A s原创 2015-05-02 11:46:56 · 715 阅读 · 0 评论 -
LeetCode-77 Combinations(组合)
LeetCode-77 Combinations(组合)Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3原创 2015-05-02 12:06:29 · 1134 阅读 · 0 评论 -
LeetCode-50 Pow(x, n)
Implement pow(x, n).觉得这道题看似简单,但是却有很多细节上容易忽略的点。在此转了别人的考虑的地方及代码 1) x取值为0时,0的正数次幂是1,而负数次幂是没有意义的;判断x是否等于0不能直接用“==”。2) 对于n取值INT_MIN时,-n并不是INT_MAX,这时需要格外小心。3) 尽量使用移位运算来代替除法运算,加快算法执行的速度。 pu转载 2015-05-02 11:05:31 · 569 阅读 · 0 评论 -
LeetCode-56 Merge Intervals(合并区间)
LeetCode-56 Merge Intervals(合并区间)Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]./** * Definition原创 2015-05-02 11:11:58 · 713 阅读 · 0 评论 -
LeetCode-67 Add Binary(二进制数相加)
LeetCode-67 Add Binary(二进制数相加)Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100". public class Solution { public String addBin原创 2015-05-02 11:18:08 · 928 阅读 · 0 评论 -
LeetCode-69 Sqrt(x)
LeetCode-69 Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.思路:二分法。比较要留意的是right left 的处理。public class Solution { public int mySqrt(int x) { if (x == 0)原创 2015-05-02 11:30:18 · 664 阅读 · 0 评论 -
LeetCode-20 Valid Parentheses(判断括号是否规范)
LeetCode-20 Valid ParenthesesGiven a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "原创 2015-04-25 11:55:04 · 810 阅读 · 0 评论 -
LeetCode-26 Remove Duplicates from Sorted Array(水题-去相同元素)
LeetCode-26 Remove Duplicates from Sorted ArrayGiven 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 fo原创 2015-04-29 17:29:39 · 1155 阅读 · 0 评论 -
LeetCode-21 Merge Two Sorted Lists(合并两个有序链表)
LeetCode-21 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. 代码:原创 2015-04-25 12:58:19 · 889 阅读 · 0 评论 -
LeetCode-11 Container With Most Water(容器装水最大量)
LeetCode-11 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 e原创 2015-04-22 15:17:01 · 632 阅读 · 0 评论 -
LeetCode-15 3Sum(求3数和为零的情况总数)
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)原创 2015-04-22 15:37:26 · 489 阅读 · 0 评论 -
LeetCode-7 Reverse Integer(倒置整型数)
LeetCode-7 Reverse IntegerReverse 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 que原创 2015-04-17 22:54:07 · 622 阅读 · 0 评论 -
LeetCode-17 Letter Combinations of a Phone Number(手机拨码-DFS)
LeetCode-17 Letter Combinations of a Phone Number(手机拨码-DFS)Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just l原创 2015-04-22 15:49:22 · 501 阅读 · 0 评论 -
LeetCode-2 Add Two Numbers
LeetCode-1 Add Two Numbers JAVA:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; *原创 2015-04-16 08:48:56 · 484 阅读 · 0 评论 -
LeetCode-5 Longest Palindromic Substring(求最长回文子串)
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.JAVA:public class So原创 2015-04-16 23:32:56 · 448 阅读 · 0 评论 -
LeetCode-3 Longest Substring Without Repeating Characters(最长无重复子串)
LeetCode-3-Longest Substring Without Repeating CharactersJAVA:import java.util.Arrays;public class Solution { public static int lengthOfLongestSubstring(String s) { int[] zimu = new int[1原创 2015-04-16 12:17:32 · 449 阅读 · 0 评论 -
LeetCode-6 ZigZag Conversion(字符串锯齿形输出)
LeetCode-6 ZigZag ConversionThe 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 legibil原创 2015-04-17 01:41:56 · 722 阅读 · 0 评论 -
leetcode难度及面试频率
1Two Sum25arraysort setTwo Pointers 2Add Two Numbers34linked listT转载 2015-04-15 01:27:00 · 687 阅读 · 0 评论 -
LeetCode-46 Permutations(全排列)
LeetCode-46 Permutations(全排列)Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],原创 2015-04-29 18:04:40 · 761 阅读 · 0 评论 -
LeetCode-19 Remove Nth Node From End of List(移除尾部第N个节点)
LeetCode-19 Remove Nth Node From End of ListGiven 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. Af原创 2015-04-25 11:45:15 · 495 阅读 · 0 评论 -
LeetCode-70 Climbing Stairs(斐波那契数列)
LeetCode-70 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 t原创 2015-05-02 11:35:31 · 1036 阅读 · 0 评论