leetcode
文章平均质量分 64
糖小狸
这个作者很懒,什么都没留下…
展开
-
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 hold addit原创 2016-07-03 17:19:27 · 167 阅读 · 0 评论 -
leetcode: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.原创 2016-07-06 15:28:45 · 219 阅读 · 0 评论 -
leetcode:Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.需要注意的是负的最大值为-2147483648,正的最大值为2147483647;因此需要将变量设置为long类型最开始我的想法是既然不能除,那就每次都减去原创 2016-07-06 13:41:42 · 204 阅读 · 0 评论 -
leetcode: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 endpoints of line i is at (i, ai) and (i,原创 2016-07-05 19:41:33 · 186 阅读 · 0 评论 -
leetcode: 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原创 2016-07-05 19:38:12 · 205 阅读 · 0 评论 -
leetcode:Valid Sudoku
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 f原创 2016-07-03 20:14:33 · 186 阅读 · 0 评论 -
leetcode: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),原创 2016-07-04 15:36:03 · 189 阅读 · 0 评论 -
leetcode :Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串。如果是,则该函数返回str2在str1中首次出现原创 2016-06-22 22:11:20 · 195 阅读 · 0 评论 -
leetcode:Longest Palindromic Substring java
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.开始我直接用了下面的蛮力解法原创 2016-06-22 16:57:10 · 166 阅读 · 0 评论 -
leetcode:Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "原创 2016-06-22 17:09:18 · 161 阅读 · 0 评论 -
leetcode:Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4原创 2016-06-18 22:08:16 · 176 阅读 · 0 评论 -
leetcode:same tree的 java实现 (两行)
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./** * Definit原创 2016-06-18 18:03:27 · 252 阅读 · 0 评论 -
Binary Tree Level Order Traversal的java实现
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 2原创 2016-06-17 22:44:24 · 295 阅读 · 0 评论 -
leetcode: Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1]public class Solution { public List getRow(int rowIndex) { int n=0;原创 2016-07-03 17:05:58 · 171 阅读 · 0 评论 -
leetcode: Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]public class Solut原创 2016-07-03 17:15:29 · 159 阅读 · 0 评论 -
leetcode:Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.开始没考虑k比链表长度大的情况,其实到现在我们不清楚为啥要考虑这种原创 2016-07-05 22:17:23 · 217 阅读 · 0 评论