![](https://img-blog.csdnimg.cn/20190927151043371.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
笔试面经 LeetCode 剑指Offer 后端/大数据
文章平均质量分 78
Top5硕士,先后在京东、字节从事后端开发、大数据开发。专栏包含各大厂后端/大数据开发岗笔试面试题目、LeetCode系列、剑指Offer系列、Java系列、数据结构系列、大数据系列、常用算法等,均为博主精心收集和整理,一些题目也是博主本人遇到。
二十六画生的博客
国内Top5硕士,先后在京东、字节从事多年后端开发、大数据开发。
展开
-
Leetcode557. Reverse Words in a String III--单词序号不变,单词中的字符倒序
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"...原创 2019-06-27 21:01:09 · 285 阅读 · 0 评论 -
LeetCode 59. Spiral Matrix II--输入一个正整数,顺时针打印从1到n^2组成二维数组
59.Spiral Matrix IIGiven a positive integern, generate a square matrix filled with elements from 1 ton^2in spiral order.Example:Input: 3Output:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]...原创 2018-11-18 12:33:43 · 607 阅读 · 0 评论 -
Leetcode 70. Climbing Stairs-每次能走1步或2步台阶,输入n,求总的方法数
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 positive...原创 2019-01-05 11:22:13 · 557 阅读 · 0 评论 -
Leetcode 66. Plus One-数组表示的数值+1,返回新的数组
Given anon-emptyarray of digitsrepresenting 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...原创 2019-01-12 11:58:12 · 386 阅读 · 1 评论 -
Leetcode 383. Ransom Note -- 判断magazine字符串中的字母能否组成ransomNote字符串,magazine中的每个字母只能用一次
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot...原创 2019-06-18 22:13:12 · 265 阅读 · 0 评论 -
Leetcode 91. Decode Ways-解析数字字符串,1表示A,2表示B,3表示C..26表示Z,能解析出多少种?输入一串数字转成A-Z字母串有多少种方法?-动态规划
Leetcode 91. Decode Ways-解析数字字符串,1表示A,2表示B,3表示C..26表示Z,能解析出多少种?输入一串数字转成A-Z字母串有多少种方法?原创 2019-06-12 15:14:12 · 1793 阅读 · 0 评论 -
LeetCode 64. Minimum Path Sum--从左上角到右下角的路径经过的元素和最小是多少,每次只能往右或往下移动一步
64.Minimum Path SumGiven amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move eit...原创 2018-11-19 22:45:38 · 813 阅读 · 0 评论 -
Leetcode 31. Next Permutation --数组的下一个(字典顺序更大的)排列
Implementnext permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible o...原创 2019-06-30 18:37:22 · 400 阅读 · 0 评论 -
Leetcode 83. Remove Duplicates from Sorted List-从有序链表中删除重复节点,重复的节点只保留一个
* 每次:head与head.next值相等时,pre.next = head.next * head与head.next值不相等时,pre=最后一个重复值,head=下一个值原创 2022-04-03 22:46:44 · 506 阅读 · 0 评论 -
Leetcode 27. Remove Element-求出不等于val的元素个数,还需要交换元素,需要前几个元素都不等于val,等于val的元素要放在数组后面
Given an arraynumsand a valueval, remove all instances of that valuein-placeand return the new length.Do not allocate extra space for another array, you must do this bymodifying the input arra...原创 2019-06-11 11:04:04 · 147 阅读 · 0 评论 -
Leetcode 237. Delete Node in a Linked List-删除链表的指定节点,不给链表的头节点
Write a function todelete a nodein a singly-linked list. You willnotbe given access to theheadof the list, instead you will be given access tothe node to be deleteddirectly.It isguaranteedthat the node to be deleted isnot a tail nodein the li...原创 2022-04-05 10:55:55 · 822 阅读 · 0 评论 -
Leetcode 328. Odd Even Linked List-奇数位节点放前面,偶数位节点放后面,按照原来的顺序
Given theheadof a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and returnthe reordered list.Thefirstnode is consideredodd, and thesecondnode iseven, and so on.Note that the relative...原创 2022-04-05 19:11:38 · 320 阅读 · 0 评论 -
Leetcode 155. Min Stack -- 设计栈,实现push,pop,top,getMin获取最小值
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() -- Ge...原创 2019-07-02 21:22:30 · 580 阅读 · 0 评论 -
Leetcode 120. Triangle--给定一个三角形,同顶部到底部的路径数字之和的最小值,可以移动到下层相邻的两个元素
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5...原创 2018-12-23 17:02:05 · 596 阅读 · 0 评论 -
LeetCode 33. Search in Rotated Sorted Array-一个原来有序的数组从中间某个元素旋转,查找某个元素是否存在,存在返回下标,反之返回-1
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found ...原创 2018-11-25 22:09:43 · 631 阅读 · 0 评论 -
LeetCode 14. Longest Common Prefix--字符串数组元素的最长公共前缀
Write a function to find the longest common prefix string amongst an array of strings."abcdefg""abcdefghijk""abcdfghijk""abcef"上面的字符串数组的最长公共前缀就是"abc"。import java.util.Arrays;public cla原创 2017-08-24 16:53:12 · 493 阅读 · 0 评论 -
Leetcode 116. Populating Next Right Pointers in Each Node--完全二叉树层次遍历后放入队列链表--Queue,LinkedList
You are given aperfect binary treewhere all leaves are on the same level, and every parent has two children. The binary tree has the following definition:struct Node { int val; Node *left; Node *right; Node *next;}Populate each next pointe..原创 2022-04-05 16:12:16 · 558 阅读 · 0 评论 -
Leetcode 93. Restore IP Addresses--解析给定数字字符串成有效IP地址,求有多少种可能
Given a string containing only digits, restore it by returning all possible valid IP address combinations.Example:Input: "25525511135"Output: ["255.255.11.135", "255.255.111.35"]import java.u...原创 2019-06-12 16:08:45 · 1316 阅读 · 0 评论 -
LeetCode 90. Subsets II--找出数组的所有子集,数组元素可能重复,但结果子集不能重复
Given a collection of integers that might contain duplicates,nums, return all possible subsets (the power set).Note:The solution set must not contain duplicate subsets.Example:Input: [1,2,2]...原创 2018-12-19 21:21:23 · 965 阅读 · 0 评论 -
Leetcode_40_CombinationSumII--数组元素组合,和为目标值,一个元素只可用一次,输出每种组合,每种组合唯一
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sum totarget.Each number incandidatesmay only be usedoncein the combination.Note:The solutio...原创 2022-05-02 10:41:44 · 318 阅读 · 0 评论 -
Leetcode 96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST's: 1 ...原创 2019-01-07 22:10:41 · 274 阅读 · 0 评论 -
Leetcode 69. Sqrt(x) -- 求整数的算术平方根,返回整数,把小数位截断
Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and only...原创 2019-01-12 16:43:06 · 649 阅读 · 0 评论 -
Leetcode 345. Reverse Vowels of a String --前后交换元音字母,包含大小写字母
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Input: "hello"Output: "holle"Example 2:Input: "leetcode"Output: "leotcede"Note:The vowel...原创 2019-06-17 09:25:09 · 373 阅读 · 0 评论 -
Leetcode 551. Student Attendance Record I--判断是否奖励: A出现次数大于1返回false;L连续出现次数大于2返回false,中间隔断时从0开始计数
You are given a string representing an attendance record for a student. The record only contains the following three characters:'A': Absent. 'L': Late. 'P': Present.A student could be rewarded...原创 2019-06-26 17:46:24 · 202 阅读 · 0 评论 -
Leetcode 387. First Unique Character in a String--返回字符串中第一个唯一字符的下标,不存在时返回-1
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note:You may...原创 2019-06-19 10:06:50 · 325 阅读 · 0 评论 -
Leetcode 151. Reverse Words in a String--倒序输出数组中的字符串,字符串中的字符不倒序
Given an input string, reverse the string word by word.Example 1:Input: "the sky is blue"Output:"blue is sky the"Example 2:Input: " hello world! "Output:"world! hello"Explanation:...原创 2019-06-12 17:30:34 · 385 阅读 · 0 评论 -
Leetcode 80. Remove Duplicates from Sorted Array II -- 删除有序数组中重复元素,重复元素最多出现2次
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.Do not allocate extra space for another array, you must do this by mod...原创 2019-06-30 11:12:06 · 558 阅读 · 0 评论 -
Leetcode 29. Divide Two Integers--两个32位整数相除,小数位截断,不能使用乘法、除法、取模运算
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The integer division sho...原创 2019-01-13 15:49:31 · 326 阅读 · 0 评论 -
Leetcode 434. Number of Segments in a String--计算连续非空格子串的个数
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.Please note that the string does not contain anynon-printablecharacters.Ex...原创 2019-06-19 15:05:15 · 306 阅读 · 0 评论 -
Leetcode 343. Integer Break-整数拆分后的多个整数,求最大乘积
Given a positive integern, break it into the sum ofat leasttwo positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input: 2Output: 1...原创 2019-01-21 21:34:14 · 1487 阅读 · 0 评论 -
LeetCode 45. Jump Game II--当前元素值表示能跳跃的最大长度,求跳跃到最后一个元素的最少跳跃次数--贪心算法
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to...原创 2018-11-13 22:44:00 · 736 阅读 · 0 评论 -
Leetcode 79. Word Search--给定一个字符串,在二维数组中遍历每一个字符,要求连续遍历相邻的元素,每个元素只能遍历一次
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically n...原创 2018-12-22 15:29:01 · 409 阅读 · 0 评论 -
LeetCode 209. Minimum Size Subarray Sum--从数组中查找某个最短子段的和大于等于s时,返回子段的长度,反之返回0
Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.Example: Input: s = 7, ...原创 2018-11-27 23:34:24 · 1029 阅读 · 0 评论 -
Leetcode 263. Ugly Number--是正数,并且质因子是2,3,5
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.Example 1:Input: 6Output: trueExplanation: 6 = 2 ×...原创 2019-01-05 16:10:03 · 361 阅读 · 0 评论 -
Leetcode 459. Repeated Substring Pattern--判断某字符串是否是某子串重复出现组成的
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Engli...原创 2019-06-11 16:06:16 · 691 阅读 · 0 评论 -
Leetcode 344. Reverse String--输入字符数组,倒序输出;旋转字符数组,倒序字符数组,反转字符数组
Leetcode 344. Reverse String--输入字符数组,倒序输出;旋转字符数组,倒序字符数组,反转字符数组原创 2019-06-15 15:47:52 · 530 阅读 · 0 评论 -
LeetCode 259. 3Sum Smaller 三数之和比target小的triplet有多少
Given an array ofnintegersnumsand atarget, find the number of index tripletsi, j, kwith0 <= i < j < k < nthat satisfy the conditionnums[i] + nums[j] + nums[k] < target.For example, givennums=[-2, 0, 1, 3], andtarget= 2.Ret...原创 2020-12-15 22:10:24 · 252 阅读 · 0 评论 -
LeetCode 74. Search a 2D Matrix--二维数组 每行有序,且当前行的首元素大于上一行的末位元素,判断是否存在某元素
74.Search a 2D MatrixMediumWrite an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right...原创 2018-11-21 22:12:42 · 383 阅读 · 0 评论 -
Leetcode 26. Remove Duplicates from Sorted Array--从有序数组中删除重复元素;从有序数组中找出不重复元素放到数组左边,返回不重复元素的个数
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 modifyi...原创 2019-06-28 22:08:59 · 409 阅读 · 0 评论 -
Leetcode 264. Ugly Number II-输出前n个丑数(从小到大)
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example:Input: n = 10Output: 12Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10...原创 2019-01-05 19:42:11 · 537 阅读 · 2 评论