
LeetCode
文章平均质量分 69
米缸没米了
小姐姐,我家米缸没大米了,能否借点大米呀!
展开
-
给定一个target,问:数组是否有两个元素的和为target;
转载:https://blog.youkuaiyun.com/u010515761/article/details/43451035题目:编写一个函数,输入为一个int型的数组numbers和一个int型变量target,找到这个数组中和为target的两个元素,输出其index。假设每组输入有且仅有一组输出示例:Input: numbers={6, 2, 15, 7,11}, target=9Output:...转载 2018-06-29 11:48:43 · 1422 阅读 · 0 评论 -
动态规划--爬楼梯
1、题目: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?Note: Given n will be a positiv...原创 2018-06-05 08:39:26 · 203 阅读 · 0 评论 -
动态规划---最好的一天买卖股票
1、题目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 stock...原创 2018-06-05 08:27:43 · 587 阅读 · 0 评论 -
动态规划--最小代价爬楼梯
1、题目:On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top ...原创 2018-06-05 08:19:23 · 907 阅读 · 0 评论 -
链表14
1、题目:Given a singly linked list 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 t...原创 2018-05-08 12:09:12 · 104 阅读 · 0 评论 -
链表13
1、题目:Given a linked list, swap every two adjacent nodes and return its head.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.Note:Your algorithm should use only con...原创 2018-05-08 11:31:47 · 124 阅读 · 0 评论 -
二叉树---反转二叉树,也就镜像二叉树
1、题目:Invert a binary tree.Example:Input: 4 / \ 2 7 / \ / \1 3 6 9Output: 4 / \ 7 2 / \ / \9 6 3 12、解答:无3、C++代码class Solution {public: TreeNode* inver...原创 2018-05-14 11:52:27 · 198 阅读 · 0 评论 -
二叉树4--求二叉树的深度
1、题目: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-05-14 11:13:40 · 433 阅读 · 0 评论 -
二叉树3---求每层结点的均值
1、题目:Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explanati...原创 2018-05-14 10:49:47 · 594 阅读 · 0 评论 -
动态规划---最大和的子集
1、题目: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-05 08:46:52 · 565 阅读 · 0 评论 -
动态规划---房子抢劫最大利润
1、题目: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 each of them is that adjacent ...原创 2018-06-05 09:01:23 · 474 阅读 · 0 评论 -
判断一个数是否是质数---埃拉托斯特尼筛法
1、题目:Count the number of prime numbers less than a non-negative number, n.Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.2、解答:这道题给定一个非负数n,让我们求小于n的...原创 2018-06-15 10:18:05 · 451 阅读 · 0 评论 -
动态规划--两字字符串的编辑距离
1、题目Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.Example 1:Input: s1 = "sea", s2 = "eat"Output: 231Explanation: Deleting "s" from "sea" adds th...原创 2018-06-06 11:37:46 · 207 阅读 · 0 评论 -
动态规划--unique paths 2
1、题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the...原创 2018-06-06 10:34:05 · 179 阅读 · 0 评论 -
动态规划----unique paths
1、题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the...原创 2018-06-06 09:43:25 · 167 阅读 · 0 评论 -
动态规划---计算等差数列的个数
1、题目:A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequen...原创 2018-06-05 11:52:48 · 1602 阅读 · 0 评论 -
动态规划---回文子串
1、题目: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 as different substrings even they consi...原创 2018-06-05 11:06:31 · 207 阅读 · 0 评论 -
动态规划--统计给定nun,从0~num每个数二进制表示时0的个数
1、题目: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 array.Example:For num = 5 yo...原创 2018-06-05 10:10:26 · 240 阅读 · 0 评论 -
动态规划---范围累加和查询
1、题目Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumR...原创 2018-06-05 09:19:28 · 206 阅读 · 0 评论 -
二叉树2---修剪二叉树线索树
1、题目:Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so t...原创 2018-05-14 10:02:36 · 247 阅读 · 0 评论 -
二叉树--合并两颗二叉树
1、题目: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 need to merge them into a new binary t...原创 2018-05-14 09:27:40 · 3136 阅读 · 0 评论 -
链表12
1、题目:奇偶问题Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do ...原创 2018-05-07 12:14:25 · 202 阅读 · 0 评论 -
链表5
1、题目:给定一个链表,判断它是否是循环链表 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?2、解答:该题目是链表是单链表,只有一个指针,所以循环一定在表尾,不存在循环...原创 2018-05-04 14:50:12 · 87 阅读 · 0 评论 -
链表4
1、题目: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-05-04 12:19:18 · 103 阅读 · 0 评论 -
链表3
1、合并链表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->4Output: 1...原创 2018-05-04 11:30:45 · 143 阅读 · 0 评论 -
链表2
1、反转链表Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or recursivel...原创 2018-05-04 10:36:45 · 101 阅读 · 0 评论 -
LeetCode---链表1
1、题目Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node w...原创 2018-05-04 09:49:05 · 131 阅读 · 0 评论 -
链表18--删除重复的元素包括自己
1、题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1->...原创 2018-05-10 12:23:04 · 136 阅读 · 0 评论 -
链表17---链表排序
1、题目:Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1->0...原创 2018-05-10 11:50:49 · 145 阅读 · 0 评论 -
链表16--两个数相加
1、题目: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-05-10 10:40:44 · 136 阅读 · 0 评论 -
链表19---循环链表,找到链表循环的起始位置
1、题目:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?2、解答: 先用两个指...原创 2018-05-11 09:54:20 · 712 阅读 · 0 评论 -
链表20---反转链表中指定的位置
1、题目:Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5-&g...原创 2018-05-11 10:49:45 · 408 阅读 · 0 评论 -
链表11
1、题目 You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and ret...原创 2018-05-07 11:57:36 · 162 阅读 · 0 评论 -
链表10
1、题目:Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list "parts".The length of each part should be as equal as possible: no two p...原创 2018-05-07 11:00:48 · 127 阅读 · 0 评论 -
链表9
1、题目:We are given head, the head node of a linked list containing unique integer values.We are also given the list G, a subset of the values in the linked list.Return the number of connected component...原创 2018-05-07 10:08:19 · 111 阅读 · 0 评论 -
链表8
1、题目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-05-05 12:07:01 · 134 阅读 · 0 评论 -
链表7
1、题目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?2、解答:给定一个链表,判断它是否是回文链表。C++的做法是 借助一个栈来存储数据,而python的经典做法是 对列表进行反转3、C++代码class Soluti...原创 2018-05-05 11:26:14 · 97 阅读 · 0 评论 -
链表6
1、Remove all elements from a linked list of integers that have value val.Example: Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->52、解答: 去除链表中指定的值,需要考虑链表中的第一个...原创 2018-05-05 10:43:16 · 124 阅读 · 0 评论 -
链表22--删除倒数第n个元素
1、题目:Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, t...原创 2018-05-11 11:52:48 · 160 阅读 · 0 评论 -
链表21 -- 分割链表
1、题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each o...原创 2018-05-11 11:17:24 · 205 阅读 · 0 评论