LeetCode
刷题记录
LYZ0907
SHOW YOUR CODE.
展开
-
【Leetcode-Medium-494】Target Sum
【Leetcode-Medium-494】Target Sum题目You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as i原创 2017-10-19 19:44:07 · 811 阅读 · 0 评论 -
【Leetcode-Medium-647】Palindromic Substrings
【Leetcode-Medium-647】Palindromic Substrings题目Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted原创 2017-10-20 20:06:57 · 811 阅读 · 0 评论 -
【Leetcode-Medium-238】Product of Array Except Self
【Leetcode-Easy-238】Product of Array Except Self题目Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nu原创 2017-10-20 21:11:45 · 689 阅读 · 0 评论 -
【Leetcode-Medium-547】Friend Circles
Leetcode-Medium-547】Friend CirclesTODO: 对比2017-09-12去哪儿校招真题”六度人脉,最大的度”题目There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For exa原创 2017-10-20 21:38:33 · 765 阅读 · 0 评论 -
【Leetcode-Medium-583】Delete Operation for Two Strings
【Leetcode-Medium-583】Delete Operation for Two Strings题目Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one原创 2017-10-20 22:02:12 · 976 阅读 · 0 评论 -
【Leetcode-Medium-22】Generate Parentheses
【Leetcode-Easy-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:[ “((()))”,原创 2017-10-21 19:49:26 · 1361 阅读 · 0 评论 -
【Leetcode-Medium-94】Binary Tree Inorder Traversal
【Leetcode-Medium-94】Binary Tree Inorder Traversal题目Given a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree [1,null,2,3], 1 \ 2 / 3retur原创 2017-10-21 20:27:10 · 1152 阅读 · 0 评论 -
Leetcode100题
Leetcode100题【Leetcode-Easy-110】Balanced Binary Tree题目Given 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原创 2017-10-16 20:00:07 · 605 阅读 · 0 评论 -
【Leetcode-Easy-110】Balanced Binary Tree
【Leetcode-Easy-110】Balanced Binary Tree题目Given 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 depth of the tw原创 2017-10-19 15:01:44 · 750 阅读 · 0 评论 -
【Leetcode-Easy-141】Linked List Cycle
【Leetcode-Easy-141】Linked List Cycle题目Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?思路快指针和慢指针程序/** * Definition for singly-linked list.原创 2017-10-19 15:03:27 · 639 阅读 · 0 评论 -
【Leetcode-Easy-20】 Valid Parentheses
【Leetcode-Easy-20】 Valid Parentheses题目Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order,原创 2017-10-19 15:05:12 · 988 阅读 · 0 评论 -
【Leetcode-Easy-234】Palindrome Linked List
【Leetcode-Easy-234】Palindrome Linked List题目Given a singly linked list, determine if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?思路双指针找到链表的中间结点; 反转链表的后半部分; 比较链表的前半部分和“后半原创 2017-10-19 15:06:04 · 646 阅读 · 0 评论 -
【Leetcode-Easy-160】Intersection of Two Linked Lists
【Leetcode-Easy-160】Intersection of Two Linked Lists题目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:原创 2017-10-19 15:06:57 · 633 阅读 · 0 评论 -
【Leetcode-Easy-155】 Min Stack
【Leetcode-Easy-155】 Min Stack题目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原创 2017-10-19 15:27:11 · 713 阅读 · 0 评论 -
【Leetcode-Medium338】Counting Bits
【Leetcode-Medium338】Counting Bits题目Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an原创 2017-10-19 19:06:28 · 907 阅读 · 0 评论 -
【Leetcode-Medium-46】Permutations
【Leetcode-Medium-46】Permutations题目Given a collection of distinct numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3],原创 2017-10-19 19:19:13 · 548 阅读 · 0 评论 -
【Leetcode-Easy-581】Shortest Unsorted Continuous Subarray
【Leetcode-Easy-581】Shortest Unsorted Continuous Subarray题目Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array w原创 2017-10-19 14:51:54 · 671 阅读 · 0 评论 -
Leetcode题目汇总-Java实现
Leetcode高频题目(100)汇总-Java实现原创 2017-10-17 08:52:51 · 1228 阅读 · 0 评论 -
【Leetcode-easy-448】Find All Numbers Disappeared in an Array
【Leetcode-easy-448】Find All Numbers Disappeared in an Array题目Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements o原创 2017-10-18 08:45:13 · 569 阅读 · 0 评论 -
【Leetcode-Easy-283】Move Zeroes
【Leetcode-Easy-283】Move Zeroes题目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,原创 2017-10-18 09:09:30 · 687 阅读 · 0 评论 -
【Leetcode-Easy-206】Reverse Linked List
【Leetcode-Easy-206】Reverse Linked List题目Reverse a singly linked list.思路双指针程序/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(in原创 2017-10-18 10:37:33 · 596 阅读 · 0 评论 -
【Leetcode-Easy-169】 Majority Element
【Leetcode-Easy-169】 Majority Element题目Given 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-原创 2017-10-18 12:39:09 · 495 阅读 · 0 评论 -
【Leetcode-Easy-121】Best Time to Buy and Sell Stock
【Leetcode-Easy-121】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原创 2017-10-18 13:31:05 · 632 阅读 · 0 评论 -
【Leetcode-Easy-70】Climbing Stairs
【Leetcode-Easy-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 top?No原创 2017-10-18 13:57:22 · 662 阅读 · 0 评论 -
【Leetcode-Easy-53】Maximum Subarray
【Leetcode-Easy-53】Maximum Subarray题目Find 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原创 2017-10-18 14:18:33 · 1396 阅读 · 0 评论 -
【Leetcode-Easy-21】Merge Two Sorted Lists
【Leetcode-Easy-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.思路巧用头结点(哑结点)程序/**原创 2017-10-18 14:27:45 · 843 阅读 · 0 评论 -
【Leetcode-Easy-198】House Robber
【Leetcode-Easy-198】House Robber题目You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing eac原创 2017-10-18 15:00:15 · 592 阅读 · 0 评论 -
【Leetcode-Easy-101】 Symmetric Tree
【Leetcode-Easy-101】 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 / \原创 2017-10-18 15:16:54 · 929 阅读 · 0 评论 -
【Leetcode-easy-543】Diameter of Binary Tree
【Leetcode-easy-543】Diameter of Binary Tree题目Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any原创 2017-10-16 19:43:07 · 783 阅读 · 0 评论 -
【Leetcode-easy-572】Subtree of Another Tree
【Leetcode-easy-572】Subtree of Another Tree题目Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree c原创 2017-10-16 21:37:14 · 670 阅读 · 0 评论 -
【Leetcode-easy-226】Invert Binary Tree
【Leetcode-easy-226】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 thi原创 2017-10-14 21:56:12 · 699 阅读 · 0 评论 -
【Leetcode-easy-136】Single Number
【Leetcode-easy-136】Single Number题目Given an 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 i原创 2017-10-14 22:10:31 · 714 阅读 · 0 评论 -
【Leetcode-easy-104】Maximum Depth of Binary Tree
【Leetcode-easy-104】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原创 2017-10-14 22:20:21 · 697 阅读 · 0 评论 -
【Leetcode-easy-111】Minimum Depth of Binary Tree
【Leetcode-easy-111】Minimum Depth of Binary Tree题目Given 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原创 2017-10-14 19:21:43 · 805 阅读 · 0 评论 -
【Leetcode-medium-150】Evaluate Reverse Polish Notation
【Leetcode-medium-150】Evaluate Reverse Polish Notation题目Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or anothe原创 2017-10-14 19:41:52 · 879 阅读 · 0 评论 -
【Leetcode-easy-617】Merge Two Binary Trees
【Leetcode-easy-617】Merge Two Binary Trees题目Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You n原创 2017-10-14 20:21:25 · 932 阅读 · 0 评论 -
【Leetcode-easy-463】Island Perimeter
【Leetcode-easy-463】Island Perimeter题目You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not原创 2017-10-14 21:40:35 · 767 阅读 · 0 评论 -
【Leetcode-hard-146】LRU Cache
【Leetcode-hard-146】LRU Cache题目Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be原创 2017-10-14 13:49:05 · 995 阅读 · 0 评论 -
【Leetcode-13】罗马数字转换为阿拉伯数字
题目罗马数字转换为阿拉伯数字思路程序package leetcode.subjects;import org.junit.Test;import java.util.HashMap;/** * description: * * @author liyazhou * @since 2017-09-20 21:58 */public class RomanToInt { @Test原创 2017-09-20 22:18:22 · 513 阅读 · 0 评论 -
Leetcode-easy题目总结-Java实现
Leetcode-easy题目总结-Java实现001组xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx002组xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx原创 2017-09-23 20:32:29 · 602 阅读 · 0 评论