Description Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [, , ] Output: Explanation: The third maximum .  E…
#-*- coding: UTF-8 -*- #l1 = ['1','3','2','3','2','1','1']#l2 = sorted(sorted(set(l1),key=l1.index,reverse=False),reverse=True)class Solution(object):    def thirdMax(self, nums):        """        :type nums: List[int]        :rtype: int  …
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - Leetcode 414. Third Maximum Number题解 在线提交: https://leetcode-cn.com/problems/third-maximum-number 题目描述 414. 第三大的数 给定一个非空数组,返回此数组中第三大的数.如果不存在,则返回数组中最大的数.…
problem 414. Third Maximum Number solution 思路:用三个变量first, second, third来分别保存第一大.第二大和第三大的数,然后遍历数组. class Solution { public: int thirdMax(vector<int>& nums) { //1.LONG_MIN; long first = LONG_MIN, second = LONG_MIN, third = LONG_MIN;// for(auto a:n…
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2, 1] Output: 1 Explanation: The third maximum is 1. Examp…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 替换最大值数组 使用set 三个变量 日期 题目地址:https://leetcode.com/problems/third-maximum-number/description/ 题目描述 Given a non-empty array of integers, return the third maximum number in this arr…
Problem: Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2, 1] Output: 1 Explanation: The third maximum is…
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2, 1] Output: 1 Explanation: The third maximum is 1. Examp…
[抄题]: Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2, 1] Output: 1 Explanation: The third maximum is 1.…
Description Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [,,,,,] Output: Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s . Note: T…
Description 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: [-,,-,,-,,,-,], Output: Explanation: [,-,,] has the largest sum = . Follow up: If you…
Description Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1: Input: [,,] Output: Example 2: Input: [,,,,,,,,] Output: Note:Your algorithm should run in linear runtime com…
题目 描述:给定数组中求第三大的数字:如果没有,返回最大的:时间复杂度O(n) 记得<剑指offer>才看到过这样的求第k大的题目.但是忘记具体怎么做了.只好先自己想了. 因为时间复杂度的限制,所以不能用排序,考虑声明3个空间,用于保存前三大的数字. 错误 三个空间初始化为N[0] 由于考虑不仔细,想着直接把三个空间初始化为N[0],然后从1开始遍历,发现可能直接输出第一个数字,尽管它不是第三大的. 所以应该初始化为Integer.MIN_VALUE 理解错题目 刚开始没有认真理解好题目,&q…
Description 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 nums1 has enough space (size that is gr…
这是小川的第次更新,第篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第267题(顺位题号是1189).给定一个字符串文本,使用文本字符来构成单词"balloon"的尽可能多的实例.每个字符最多可以在文本中使用一次.返回可以形成的最大实例数. 例如: 输入:text = "nlaebolko" 输出:1 输入:text = "loonbalxballpoon" 输出:2 输入:text = "leetcode&qu…
Description 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. Example: Input: [,,,,] Output: [,,,,] Note: You must do this in-place without making a copy of the array…
Description 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 numbers such that they add up to the target, wh…
Description 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., buy one and sell one share of the stock multi…
Description 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 element in the array contain a single digit. Y…
给定一个非空数组,返回此数组中第三大的数.如果不存在,则返回数组中最大的数.要求算法时间复杂度必须是O(n).示例 1:输入: [3, 2, 1]输出: 1解释: 第三大的数是 1.示例 2:输入: [1, 2]输出: 2解释: 第三大的数不存在, 所以返回最大的数 2 .示例 3:输入: [2, 2, 3, 1]输出: 1解释: 注意,要求返回第三大的数,是指第三大且唯一出现的数.存在两个值为2的数,它们都排第二.详见:https://leetcode.com/problems/third-m…
Description 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 of [1, n] inclusive that do not appear in this array. Could you do it without extra space and in O…
---恢复内容开始--- Description Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k. Example 1: Input: nums =…
Description Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Example 1: Input: [,,,] Out…
---恢复内容开始--- Description Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps t…
Description 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 directly above it. Example: Input: Output…
Description Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it. Example: Input: Output: [ [], [,], [,,], [,,,], [,,,,] ] 题目描述,给定一个数量…
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 array in-place with O(1) extra memory. The order of ele…
Description 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 modifying the input array in-place with O(1) e…
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 same element twice. Example: Given nums = [, , , ], targ…
这个题有点坑啊..主要是自己蠢,以为 Integer.MIN_VALUE -1 == -2147483649 public class Solution { public int thirdMax(int[] nums) { long max = (long)Integer.MIN_VALUE-1, mid = (long)Integer.MIN_VALUE-1, min = (long)Integer.MIN_VALUE-1; for(int j: nums) { long i = (long…