![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
每日LeetCode
Iron~Man
做自己喜欢的事
展开
-
LeetCode算法面试题汇总之开始之前(5): 鸡蛋掉落
你将获得K个鸡蛋,并可以使用一栋从1到N共有N层楼的建筑。每个蛋的功能都是一样的,如果一个蛋碎了,你就不能再把它掉下去。你知道存在楼层F,满足0 <= F <= N任何从高于F的楼层落下的鸡蛋都会碎,从F楼层或比它低的楼层落下的鸡蛋都不会破。每次移动,你可以取一个鸡蛋(如果你有完整的鸡蛋)并把它从任一楼层X扔下(满足1 <= X...原创 2019-11-07 10:54:25 · 103 阅读 · 0 评论 -
LeetCode算法面试题汇总之开始之前(4): 合并两个有序数组
给定两个有序整数数组nums1和nums2,将nums2合并到nums1中,使得num1成为一个有序数组。说明:初始化nums1和nums2的元素数量分别为m和n。 你可以假设nums1有足够的空间(空间大小大于或等于m + n)来保存nums2中的元素。示例:输入:nums1 = [1,2,3,0,0,0], m = 3nums2 ...原创 2019-11-07 10:50:07 · 93 阅读 · 0 评论 -
LeetCode算法面试题汇总之开始之前(3): 搜索二维矩阵 II
编写一个高效的算法来搜索mxn矩阵 matrix 中的一个目标值 target。该矩阵具有以下特性:每行的元素从左到右升序排列。 每列的元素从上到下升序排列。示例:现有矩阵 matrix 如下:[ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 1...原创 2019-11-07 10:48:28 · 190 阅读 · 0 评论 -
LeetCode算法面试题汇总之开始之前(2):求众数
给定一个大小为n的数组,找到其中的众数。众数是指在数组中出现次数大于⌊ n/2 ⌋的元素。你可以假设数组是非空的,并且给定的数组总是存在众数。示例1:输入: [3,2,3]输出: 3示例2:输入: [2,2,1,1,1,2,2]输出: 2解题思路:首先计算数组长度除以二,得到达到众数的频率。然后用字典key是数组元素,value是元素的出现次数。最后...原创 2019-11-07 10:46:19 · 92 阅读 · 0 评论 -
LeetCode算法面试题汇总之开始之前(1):只出现一次的数字
给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。说明:你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?示例 1:输入: [2,2,1]输出: 1示例2:输入: [4,1,2,1,2]输出: 4解题思路:我用的是Python的字典,key为数组里的数字,value是数字的出现次数,当重复...原创 2019-11-07 10:43:15 · 146 阅读 · 0 评论 -
LeetCode 108. Convert Sorted Array to Binary Search Tree C++
题目描述: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...原创 2018-12-10 21:40:45 · 142 阅读 · 0 评论 -
LeetCode 112. Path Sum C语言
题目描述:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note: A leaf is a node with no children.E...原创 2018-12-10 21:55:38 · 139 阅读 · 0 评论 -
LeetCode 110. Balanced Binary Tree java
题目描述: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 two subtrees of every node nev...原创 2018-12-18 21:11:48 · 187 阅读 · 0 评论 -
LeetCode 111. Minimum Depth of Binary Tree java
题目描述: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 node.Note: A leaf is a node with no ...原创 2018-12-18 21:26:33 · 236 阅读 · 1 评论 -
141. Linked List Cycle C语言
题目描述:Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where ...原创 2019-02-12 12:45:39 · 145 阅读 · 0 评论 -
155. Min Stack C++
题目描述: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(...原创 2019-02-12 19:45:07 · 154 阅读 · 0 评论 -
从尾到头输出链表。
题目描述:输入一个链表的头结点,从尾到头反过来输出每个结点的值。链表结点定义如下:struct ListNode{ int m_nKey; ListNode* m_pNext;};解题思路:方法一:借用栈倒序输出链表因为栈是先进后出,把链表中的元素存进栈中,链表前面的元素在栈底,后面的元素在栈顶,链表后面的元素先出栈。方法...原创 2019-05-05 21:53:24 · 524 阅读 · 0 评论 -
字符串的排列
题目描述:输入一个字符串,打印出该字符串中字符的所有排列。例如输入字符串“abc”,则打印出由a、b、c所能排列出来的所有字符串abc、acb、bac、bca、cab和cba。解题思路:我们解这题时可以将字符串划分为两部分:首字符和后面的所有字符。首先求所有可能出现在第一个位置的字符,即把首字符和后面的字符交换。下图是字符串abc所有字符出现在第一个位置的情形:然后对后...原创 2019-05-05 22:05:37 · 89 阅读 · 0 评论 -
一笔画问题
题目描述zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来。规定,所有的边都只能画一次,不能重复画。输入第一行只有一个正整数N(N<=10)表示测试数据的组数。每组测试数据的第一行有两个正整数P,Q(P<=1000,Q<=2000),分别表示这个画中有多少个顶点和多少条连线。(点的编号从1到P)随后的Q行,...原创 2019-05-07 10:31:29 · 541 阅读 · 0 评论 -
LeetCode 101. Symmetric Tree C++
题目描述:101. Symmetric TreeEasy166233Given 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:...原创 2018-12-09 22:33:25 · 114 阅读 · 0 评论 -
LeetCode 88. Merge Sorted Array C语言
题目描述: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 ass...原创 2018-12-09 22:18:35 · 337 阅读 · 0 评论 -
LeetCode 27. Remove Element(C语言)
给定数组、数组长度和值,删除该值的所有实例并返回新的长度。不要为另一个数组分配额外的空间,您必须使用常量内存来执行此操作。元素的顺序可以改变。无论你离开新的长度什么都不重要。示例:给定输入数组nums = [3,2,2,3],val =3你的函数应该返回length = 2,num的前两个元素为2。比较简单,代码如下:int removeElement(int* num...原创 2018-11-21 21:39:36 · 147 阅读 · 0 评论 -
LeetCode 第七题 Reverse Integer 反转数并且判断溢出
题目Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are...转载 2018-11-19 21:42:32 · 224 阅读 · 0 评论 -
LeetCode 28. Implement strStr() C语言
题目描述:Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.意思就是找到匹配字符串开始的位置,kmp算法。我的代码:int strStr(char* haystack, char* ...原创 2018-11-22 21:30:19 · 120 阅读 · 0 评论 -
LeetCode 35. Search Insert Position C语言
问题描述: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 a...原创 2018-11-22 21:50:48 · 85 阅读 · 0 评论 -
LeetCode 53. Maximum Subarray C语言
题目描述: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: 6Ex...原创 2018-11-25 21:51:14 · 105 阅读 · 0 评论 -
LeetCode 67. Add Binary C++
题目描述: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...原创 2018-11-28 21:46:29 · 204 阅读 · 0 评论 -
LeetCode 70. Climbing Stairs C语言
题目描述: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 p...原创 2018-11-27 13:31:30 · 156 阅读 · 0 评论 -
LeetCode 83. Remove Duplicates from Sorted List C语言
题目描述: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->3Out...原创 2018-12-04 20:49:54 · 171 阅读 · 0 评论 -
LeetCode 100. Same Tree C语言
题目描述: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.E...原创 2018-12-04 21:53:39 · 176 阅读 · 0 评论 -
LeetCode 104. Maximum Depth of Binary Tree C语言
题目描述: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 ...原创 2018-12-05 21:45:26 · 93 阅读 · 0 评论 -
LeetCode 121. Best Time to Buy and Sell Stock C语言
题目描述: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 ...原创 2018-12-13 20:47:38 · 126 阅读 · 0 评论 -
LeetCode 122. Best Time to Buy and Sell Stock II C语言
题目描述:Say 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 many transactions as you like (i.e.,...原创 2018-12-13 20:52:04 · 89 阅读 · 0 评论 -
LeetCode 136. Single Number C语言
题目描述: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 wit...原创 2018-12-14 18:20:52 · 158 阅读 · 0 评论 -
LeetCode 26. Remove Duplicates from Sorted Array
Given a sorted array, 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 in place with c...原创 2018-11-21 21:25:16 · 99 阅读 · 0 评论