LeetCode
woaily1346
这个作者很懒,什么都没留下…
展开
-
[LeetCode]第一题:求两数之和
题目描述:Given 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 may not use the sa...原创 2018-06-24 16:40:15 · 105 阅读 · 0 评论 -
[LeetCode]第三十一题 :两个排序数组的中间值
题目描述:(困难难度)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)).Example 1:nums1 = [...原创 2018-07-16 15:07:30 · 670 阅读 · 0 评论 -
[LeetCode]第十六题 :对称树
题目描述: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 3But...原创 2018-07-03 16:58:59 · 149 阅读 · 0 评论 -
[LeetCode]第十七题 :树的深度
题目描述: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.Note: A leaf is a node with no childr...原创 2018-07-03 19:31:17 · 155 阅读 · 0 评论 -
[LeetCode]第二十五题 :循环链表
题目描述:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?题目解释:给出一个链表,判断它中间是否含有循环。跟进:你能否在不使用额外空间的情况下解决它。题目解法:1.我的解法。判断是否有循环,那就判断同一个节点是否出现两次,我借助一个...原创 2018-07-10 18:55:16 · 131 阅读 · 0 评论 -
[LeetCode]第二十六题 :最小栈
题目描述:Design 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 stack.top() -- Get...原创 2018-07-10 19:23:01 · 100 阅读 · 0 评论 -
[LeetCode]第十八题 :遍历树
题目描述:Given 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).For example:Given binary tree [3,9,20,null,null,15...原创 2018-07-04 10:05:51 · 128 阅读 · 0 评论 -
[LeetCode]第二十七题 :两个链表交叉
题目描述:Write 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 → a2 ↘ ...原创 2018-07-11 15:13:52 · 180 阅读 · 0 评论 -
[LeetCode]第二十八题 :两数之和II - 输入排序数组
题目描述:Given 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 indices of the two numbe...原创 2018-07-11 15:30:19 · 159 阅读 · 0 评论 -
[LeetCode]第二十九题 :两数相加
题目描述:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ret...原创 2018-07-11 16:31:20 · 121 阅读 · 0 评论 -
[LeetCode]第十九题 :有序数组转换成平衡二叉树
题目描述:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of ...原创 2018-07-05 15:07:50 · 1780 阅读 · 0 评论 -
[LeetCode]第二十题 :帕斯卡三角
题目描述:Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.Example:Input: 5Output:[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]题目解释:给出一个数字,求出来这个数字高度的...原创 2018-07-05 16:02:23 · 144 阅读 · 0 评论 -
[LeetCode]第三十题 :没有相同字符的最大子串
题目描述:(中等难度)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 "b",...转载 2018-07-12 20:04:41 · 139 阅读 · 0 评论 -
[LeetCode]第二十一题 :帕斯卡三角 II
题目描述:Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.Note that the row index starts from 0.In Pascal's triangle, each number is the sum of the two numbers ...原创 2018-07-06 15:08:50 · 113 阅读 · 0 评论 -
[LeetCode]第二十二题 :最佳时机买卖股票
题目描述: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 (i.e., buy one and sell one share of the stoc...原创 2018-07-06 16:46:47 · 131 阅读 · 0 评论 -
[LeetCode]第二十四题 :单个数
题目描述:Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u...原创 2018-07-09 22:54:57 · 151 阅读 · 0 评论 -
[LeetCode]第二十三题 :有效回文
题目描述:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome.Exam...原创 2018-07-09 22:27:01 · 124 阅读 · 0 评论 -
[LeetCode]第十二题 :二进制相加
题目描述:Given two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Example 1:Input: a = "11", b = "1"Output: "100"Example ...原创 2018-06-27 20:36:34 · 173 阅读 · 0 评论 -
[LeetCode]第二题:数字反转
题目描述:Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input:121Output:trueExample 2:Input:-121Output:falseExample 3:Input:1...原创 2018-06-24 16:45:14 · 120 阅读 · 0 评论 -
[LeetCode]第三题 :最大字符串前驱
题目描述:Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input:["flower","flow","flight"]Output:"f...原创 2018-06-24 16:50:37 · 166 阅读 · 0 评论 -
[LeetCode]第四题:开闭区间
题目描述:Given a string containing just the characters '(',')','{', '}','[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of bra...原创 2018-06-24 16:53:53 · 588 阅读 · 0 评论 -
[LeetCode]第五题:合并两个有序链表
题目描述: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.Example:Input:1 -> 2 -> 4,1 -> 3 -> 4Outpu...原创 2018-06-24 16:56:41 · 94 阅读 · 0 评论 -
[LeetCode]第六题 :去掉重复值
题目描述:Given a sorted array nums, 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 by modi...原创 2018-06-24 16:59:21 · 205 阅读 · 0 评论 -
[LeetCode]第七题 :去掉重复值
题目描述:Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input a...原创 2018-06-25 18:51:31 · 123 阅读 · 0 评论 -
[LeetCode]第八题 :求字符串索引
题目描述: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 = "hello", needle = "ll"Output: 2题目解释:实现strSt...原创 2018-06-25 19:27:47 · 470 阅读 · 0 评论 -
[LeetCode]第八题 :求数字在数组中的位置
题目描述: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...原创 2018-06-25 19:41:15 · 631 阅读 · 0 评论 -
[LeetCode]第九题 :求几个连续数字最大和
题目描述:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanati...原创 2018-06-26 20:22:22 · 915 阅读 · 0 评论 -
[LeetCode]第十题 :求最后一个单词的长度
题目描述: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 is defi...原创 2018-06-26 20:31:39 · 298 阅读 · 0 评论 -
[LeetCode]第十三题 :移除相同的值
题目描述:Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1->2-...原创 2018-07-02 18:59:53 · 100 阅读 · 0 评论 -
[LeetCode]第十四题 :合并两个有序数组
题目描述:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively.You may assume that...原创 2018-07-02 19:35:57 · 385 阅读 · 0 评论 -
[LeetCode]第十五题 :相同树
题目描述:Given 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 have the same value.Example...原创 2018-07-02 20:03:40 · 125 阅读 · 0 评论 -
[LeetCode]第十一题 :数字+1
题目描述:Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each elem...原创 2018-06-27 19:58:22 · 192 阅读 · 0 评论 -
[LeetCode]第三十二题 :锯齿形变换
题目描述:(中等难度)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 ...原创 2018-08-03 17:55:13 · 219 阅读 · 0 评论