寒假学习日记
yittah
这个作者很懒,什么都没留下…
展开
-
Day9 Minimum Depth of Binary Tree
LeetCode111. Minimum Depth of Binary TreeGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.(...原创 2018-02-08 17:20:35 · 97 阅读 · 0 评论 -
Day0 Two Sum
LeetCode:1.Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you m原创 2018-01-29 21:48:56 · 169 阅读 · 0 评论 -
Day0
明日复明日,明日何其多,我生待明日,万事成蹉跎。世人若被明日累,春去秋来老将至。朝看水东流,暮看日西坠。学习!原创 2018-01-29 20:17:32 · 134 阅读 · 0 评论 -
Day7 Binary Tree Level Order Traversal II
LeetCode107. Binary Tree Level Order Traversal IIGiven a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root原创 2018-02-05 18:45:58 · 130 阅读 · 0 评论 -
Day11 Path Sum II
LeetCode 113. Path Sum IIGiven a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.意思是找出从根结点到某叶结点的和等于sum,并记录这些路径在数组里。我的思路是,利用栈来深度优先遍历二叉树,将这个遍历路径记录在一个数组temp...原创 2018-02-09 19:20:26 · 104 阅读 · 0 评论 -
Day12. Valid Palindrome
LeetCode125. Valid PalindromeGiven 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."...原创 2018-02-10 12:57:36 · 93 阅读 · 0 评论 -
Day12 Single Number
LeetCode136. Single NumberGiven an array of integers, every element appears twice except for one. Find that single one.意思是找出数组中唯一一个只出现了一次的数。如果没有什么要求的话,可以先对数组进行排序,这样的话只需要判断当前位置的数与后面的数是否相等就ok了。然而题目说最好在O...原创 2018-02-10 13:23:53 · 93 阅读 · 0 评论 -
Day12 Linked List Cycle
LeetCode141. Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?意思是判断这个链表里是否有环,并且在不用额外空间的情况下完成。思路来源于生活,当我们跑步的时候,如果跑道是一个圈,那么一直...原创 2018-02-10 13:57:49 · 108 阅读 · 0 评论 -
Day12 Best Time to Buy and Sell Stock II
LeetCode122 Best Time to Buy and Sell Stock IISay 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...原创 2018-02-10 12:29:55 · 116 阅读 · 0 评论 -
Day11 Best Time to Buy and Sell Stock
LeetCode121. Best Time to Buy and Sell StockSay 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, b...原创 2018-02-09 21:09:57 · 102 阅读 · 0 评论 -
Day1 Reverse Integer
7.Reverse IntegerGiven a 32-bit signed integer, reverse digits of an integer.Example 1: Input: -123Output: -321Example 2: Input: 120Output: 21Note:Assume we are dealing wit原创 2018-01-30 12:49:55 · 126 阅读 · 0 评论 -
Day1 Palindrome Number
9. Palindrome NumberDetermine whether an integer is a palindrome. Do this without extra space.思路:把数字串转化为字符串,从首尾开始比较起,直到比较完为止。注意要求是不要用额外的空间。负数的话,是不可能形成回文数的,所以用字符串处理没毛病。然后,基于上一篇中reverse原创 2018-01-30 14:07:38 · 119 阅读 · 0 评论 -
Day14 Factorial Trailing Zeroes
LeetCode172. Factorial Trailing ZeroesGiven an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.意思是求给定的数n的阶乘有多少个后缀0.阶乘的话,在数n之内,含有0的数,以...原创 2018-02-12 23:03:53 · 93 阅读 · 0 评论 -
Day14 Excel Sheet Column Number
LeetCode171. Excel Sheet Column NumberRelated to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 ...原创 2018-02-12 22:08:07 · 100 阅读 · 0 评论 -
Day14 Majority Element
LeetCode169. Majority ElementGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty an...原创 2018-02-12 21:24:36 · 113 阅读 · 0 评论 -
Day8 Balanced Binary Tree
LeetCode110. Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the dep原创 2018-02-06 23:16:40 · 114 阅读 · 0 评论 -
Day8 Convert Sorted Array to Binary Search Tree
LeetCode108:Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced b原创 2018-02-06 22:49:28 · 113 阅读 · 0 评论 -
Day13 Excel Title
LeetCode168. Excel TitleGiven a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 ...原创 2018-02-11 23:12:53 · 117 阅读 · 0 评论 -
Day13 Two Sum II
LeetCode167. Two Sum IIGiven an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indice...原创 2018-02-11 22:06:02 · 148 阅读 · 0 评论 -
Day13 Min Stack
LeetCode155. Min StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the s...原创 2018-02-11 19:52:17 · 99 阅读 · 0 评论 -
Day13 intersection-of-two-linked-lists
LeetCode160. intersection-of-two-linked-listsWrite 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 → ...原创 2018-02-11 21:28:10 · 141 阅读 · 0 评论 -
Day11 Pascal's Triangle II
LeetCode 119. Pascal's Triangle IIGiven an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra ...原创 2018-02-09 20:22:54 · 110 阅读 · 0 评论 -
Day11 Pascal's Triangle
LeetCode118. Pascal's TriangleGiven 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]]很简单,递推...原创 2018-02-09 19:55:47 · 90 阅读 · 0 评论 -
Day7 Maximum Depth of Binary Tree
LeetCode104. Maximum Depth of Binary Tree题目的意思是求二叉树的高度,左子树和右子树中最高的那一颗的高度加1就是二叉树的高度了。原创 2018-02-05 12:07:26 · 89 阅读 · 0 评论 -
Day4 Maximum Subarray
LeetCode53.Maximum SubarrayFind 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 co原创 2018-02-02 22:26:56 · 103 阅读 · 0 评论 -
Day4 Count and Say
LeetCode38.Count and SayThe count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off a原创 2018-02-02 20:41:57 · 99 阅读 · 0 评论 -
Day3 Search Insert Position
LeetCode35.Search Insert PositionGiven 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原创 2018-02-01 22:01:49 · 86 阅读 · 0 评论 -
Day3 Implement strStr()
LeetCode28 Implement strStr()Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1: Input: haystack = "h原创 2018-02-01 19:48:40 · 91 阅读 · 0 评论 -
Day2 Remove Elements
LeetCode27.Remove ElementGiven an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do th原创 2018-01-31 22:41:13 · 90 阅读 · 0 评论 -
Day2 Remove Duplicates from Sorted Array
LeetCode26:Remove Duplicates from Sorted ArrayGiven a sorted array, remove the duplicates in-place such that each element appear onlyonce and return the new length.Do not allocate extra sp原创 2018-01-31 22:04:01 · 136 阅读 · 0 评论 -
Day2 Merge Two Sorted Lists
LeetCode21:Merge Two Sorted ListsMerge 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.Example: Inp原创 2018-01-31 14:57:56 · 116 阅读 · 0 评论 -
Day2 Valid Parentheses
LeetCode20.Valid parenthesesGiven a string containing just the characters '(',')', '{','}', '[' and']', determine if the input string is valid.The brackets must close in the correct or原创 2018-01-31 13:56:56 · 123 阅读 · 0 评论 -
Day1 Longest Common Prefix
LeetCode 14.Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.意思是求字符串数组中所有字符串的共同前缀。思路是从首字母开始依次检查每个字符串,如果每个字符串的相同位置上的字符都相同,那么这就是共同前原创 2018-01-30 20:54:39 · 127 阅读 · 0 评论 -
Day5 Length of Last Word
LeetCode58: Length of Last WordGiven 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原创 2018-02-03 18:09:49 · 95 阅读 · 0 评论 -
Day5 Add Binary
LeetCode67:Add BinaryGiven two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 计算两个二进制的和。和前一篇plus one的思路一样,只需要考虑进位的情况就好了。用一个temp来保原创 2018-02-03 20:39:16 · 115 阅读 · 0 评论 -
Day7 Symmetric Tree
LeetCode101 . Symmetric TreeGiven 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原创 2018-02-05 11:58:17 · 129 阅读 · 0 评论 -
Day6 Same Tree
LeetCode100. Same TreeGiven two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes h原创 2018-02-04 13:56:27 · 102 阅读 · 0 评论 -
Day6 Merge Sorted Array
LeetCode88. Merge Sorted ArrayGiven two sorted integer arrays nums1 and nums2, merge nums2 intonums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is gr原创 2018-02-04 13:19:53 · 103 阅读 · 0 评论 -
Day6 Remove Duplicates from Sorted List
LeetCode83. Remove Duplicates from Sorted ListGiven a sorted linked list, delete all duplicates such that each element appear onlyonce. For example,Given 1->1->2, return 1->2.Given 1->1-原创 2018-02-04 12:25:18 · 126 阅读 · 0 评论 -
Day6 Climbing Stairs
LeetCode70,Climbing StairsYou 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?原创 2018-02-04 11:40:27 · 106 阅读 · 0 评论