lintCode 31 题解数组划分
给出一个整数数组 nums 和一个整数 k。
划分数组
原创
2022-06-23 09:44:04
48阅读
lintCode31题解数组划分中文English给出一个整数数组nums和一个整数k。划分数组(即移动数组nums中的元素),使得:所有小于k的元素移到左边所有大于等于k的元素移到右边返回数组划分的位置,即数组中第一个位置i,满足nums[i]大于等于k。样例例1:输入:[],9输出:0例2:输入:[3,2,2,1],2输出:1解释:真实的数组为[1,2,2,3].所以返回1挑战使用O(n)的时
转载
2021-06-08 11:53:26
191阅读
个人博客:枫之羽目录前言入门题37. 反转一个3位整数145. 大小写转换452. 删除链表中的元素454. 矩阵面积463. 整数排序466. 链表节点计数479. 数组第二大数484. 交换数组两个元素763. 进制转换632. 二叉树的最大节点简单题1. A + B 问题2. 尾部的零6. 合并排序数组 II8. 旋转字...
原创
2021-07-06 15:57:41
209阅读
思路: 最简单的方法,依次遍历比较就可以了。 AC代码:/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * t...
原创
2021-07-27 13:52:50
121阅读
这些一次遍历搞定的,套路无非都是在遍历的时候就记录数据的状态,然后根据遍历到的当前的数据的状态来修改最终结果,当遍历完了的时候结果也就确定了。 题目来源: http://www.lintcode.com/zh-cn/problem/longest-words/
原创
2021-07-27 13:52:47
178阅读
【题目描述】For a given source string and a target string, you should output the first index(from 0) of target string in source string.If target does not exist in source, just return -1.对于一个给定的 source 字符串和一
原创
2017-04-25 17:19:41
541阅读
【题目描述】Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.给定一个数字三角形,找到从顶部到底部的最小路径和。每一步可以移动到下面一行的相邻数字上。【注】:如果你只用额外空间复杂度O(n)的条件下完成
转载
2017-11-20 13:12:33
418阅读
【题目描述】Thesizeofthehashtableisnotdeterminateattheverybeginning.Ifthetotalsizeofkeysistoolarge(e.g.size>=capacity/10),weshoulddoublethesizeofthehashtableandrehasheverykeys.Sayyouhaveahashtablelooksli
转载
2017-12-17 13:09:07
841阅读
【题目描述】Givenanintegerarray,heapifyitintoamin-heaparray.ForaheaparrayA,A[0]istherootofheap,andforeachA[i],A[i2+1]istheleftchildofA[i]andA[i2+2]istherightchildofA[i].给出一个整数数组,堆化操作就是把它变成一个最小堆数组。对于堆数组A,A[0
转载
2017-12-18 13:10:11
954阅读
【题目描述】Given a list of numbers, return all possible permutations.Notice:You can assume that there is no duplicate numbers in the list.给定一个数字列表,返回其所有可能的排列。注意:你可以假设没有重复数字。【题目链接】http://www.lintcode.com/en
原创
2017-04-27 22:37:18
536阅读
【题目描述】Givennitems with size Ai, an integermdenotes the size of a backpack. How full you can fill this backpack?在n个物品中挑选若干物品装入背包,最多能装多满?假设背包的大小为m,每个物品的大小为A[i]【注】:你不可以将物品进行切割。【题目链接】www.lintcode.com/en/p
转载
2017-10-28 08:53:39
541阅读
【题目描述】GivennitemswithsizeAiandvalueVi,andabackpackwithsizem.What'sthemaximumvaluecanyouputintothebackpack?给出n个物品的体积A[i]和其价值V[i],将他们装入一个大小为m的背包,最多能装入的总价值有多大?【注】:A[i],V[i],n,m均为整数。你不能将物品进行切分。你所挑选的物品
转载
2017-12-14 23:06:03
411阅读
【题目描述】Given a set of distinct integers, return all possible subsets.Notice:Elements in a subset must be in non-descending order;The solution set must not contain duplicate subsets.给定一个含不同整数的集合,返回其所有的子
原创
2017-04-28 23:10:56
734阅读
【题目描述】Write an algorithm which computes the number of trailing zeros in n factorial.设计一个算法,计算出n阶乘中尾部零的个数。【题目链接】http://www.lintcode.com/en/problem/trailing-zeros/【题目解析】传统解法是首先求出n!,然后计算末尾0的个数。(重复÷10,直到余
原创
2017-04-08 13:03:59
619阅读
【题目描述】Count the number of k's between 0 and n. k can be 0 - 9.计算数字k在0到n中的出现的次数,k可能是0~9的一个值。【题目链接】http://www.lintcode.com/en/problem/digit-counts/【题目解析】方法一: Brute Force, 0到n个数挨个算过去。最大的问题就是效率,当n非常大时,就需要
原创
2017-04-11 08:51:36
379阅读
【题目描述】Given a list of numbers that may has duplicate numbers, return all possible subsetsNotice:Each element in a subset must be in non-descending order.The ordering between two subsets is free.The so
原创
2017-04-29 16:35:45
834阅读
【题目描述】Throw n dices, the sum of the dices' faces is S. Given n, find the all possible value of S along with its probability.Notice:You do not care about the accuracy of the result, we will help you to
原创
2017-04-30 21:32:25
1400阅读
题目描述】Given a non-overlapping interval list which is sorted by start point.Insert a new interval into it, make sure the list is still in order and non-overlapping (merge intervals if necessary).给出一个无重叠
原创
2017-05-07 21:32:21
503阅读
【题目描述】Given an array nums of integers and an int k, partition the array (i.e move the elements in "nums") such that:All elements < k are moved to the left;All elements >= k are moved to the righ
原创
2017-05-19 22:20:26
618阅读
【题目描述】Given an array of integers, find a contiguous subarray which has the largest sum.Notice:The subarray should contain at least one number.给定一个整数数组,找到一个具有最大和的子数组,返回其最大和。注意:子数组最少包含一个数【题目链接】http://ww
原创
2017-06-27 00:25:29
833阅读