【【leetcode刷题】[简单]189. 旋转数组(rotate array)-java】教程文章相关的互联网学习教程文章

LeetCode第[42]题(Java):Trapping Rain Water【代码】【图】

题目:接雨水难度:hard题目内容:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image!Example:Input: [0,1,0,2,1,0,1,3...

LeetCode1046 最后一块石头的重量(贪心—Java优先队列简单应用)【代码】

题目:有一堆石头,每块石头的重量都是正整数。每一回合,从中选出两块最重的石头,然后将它们一起粉碎。假设石头的重量分别为 x 和 y,且 x <= y。那么粉碎的可能结果如下:如果 x == y,那么两块石头都会被完全粉碎;如果 x != y,那么重量为 x 的石头将会完全粉碎,而重量为 y 的石头新重量为 y-x。最后,最多只会剩下一块石头。返回此石头的重量。如果没有石头剩下,就返回 0。 提示:1 <= stones.length <= 301 <= stones[i] ...

[LeetCode] 034. Search for a Range (Medium) (C++/Java)

索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode035. Search for a Range (Medium) 链接:题目:https://leetcode.com/problems/search-for-a-range/ 代码(github):https://github.com/illuz/leetcode题意:在有序数组中找到一个数的范围。(由于数有反复)分析:还是二分搜索变形。(C++)直接用 C++ STL 的 lower_bound 和 upper_bound 偷懒。(Java)直接从普通的二分改一下...

[LeetCode-JAVA] Remove Duplicates from Sorted List II 优化版【代码】

题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1->2->3, return 2->3. 原始思路:保存前一位的指针,这样在重复的时候,可以直接用next指向新的位置,需要注意的是开始时候,需要进行额外的判断是否有重复,才能形成错位的指针。原始代码:publicclass Solution {p...

Word Ladder leetcode java

题目: Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: Only one letter can be changed at a timeEach intermediate word must exist in the dictionary For example,Given:start = "hit"end = "cog"dict = ["hot","dot","dog","lot","log"] As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog", return its...

【LeetCode-面试算法经典-Java实现】【139-Word Break(单词拆分)】【代码】【图】

【139-Word Break(单词拆分)】【LeetCode-面试算法经典-Java实现】【全部题目文件夹索引】原题  Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = "leetcode", dict = ["leet", "code"]. Return true because "leetcode" can be segmented as "leet code". 题目大意  给定一个字符串s和单词字典...

Container With Most Water leetcode java

题目:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not slant the container. 题解: 这道题挺类似二分查找法的,这道题是先从两头开始...

LeetCode【2】. Add Two Numbers--java实现

第二道题Add Two Numbers 如下: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 简单来说,给两个单向链表,元素反向相加并以同样规则进行储存。注意进位! 一下是...

【LeetCode-面试算法经典-Java实现】【059-Spiral Matrix II(螺旋矩阵II)】【代码】【图】

【059-Spiral Matrix II(螺旋矩阵II)】【LeetCode-面试算法经典-Java实现】【全部题目文件夹索引】原题  Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the following matrix:[[ 1, 2, 3 ],[ 8, 9, 4 ],[ 7, 6, 5 ] ]题目大意  给定一个整数n。生成一个n*n的矩阵,用1-n^2的数字进行螺旋填充。解题思路  採用计算生成法...

[LeetCode][Java] Restore IP Addresses

题目:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example: Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)题意:给定一个只包含数字的字符串,返回有这个字符串构成的所有的有效的IP地址。比如:给定"25525511135",返回["255.255.11.135","255.255.111.35"].(顺序不计) 算法分析: * IP分为4段,每一段的...

LeetCode算法题-Find All Anagrams in a String(Java实现)【代码】

这是悦乐书的第228次更新,第240篇原创01 看题和准备今天介绍的是LeetCode算法题中Easy级别的第95题(顺位题号是438)。给定一个字符串s和一个非空字符串p,找到s中p的字谜的所有起始索引。字符串仅由小写英文字母组成,字符串s和p的长度不会大于20,100。输出顺序无关紧要。例如:输入:s:“cbaebabacd” p:“abc” 输出:[0,6]说明: 起始索引等于0的子字符串是“cba”,它是“abc”的字谜。 起始索引等于6的子字符串是“bac”,...

leetcode 150. Evaluate Reverse Polish Notation ------ java【代码】

Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6 就是求逆波兰表达式(后续遍历)的结果。1、直接求解,很慢publicclass Solution {publicint evalRPN(String[] tokens) {int len = tok...

[LeetCode][JavaScript]Combination Sum III【代码】

Combination Sum IIIFind all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers within the set are sorted in ascending order.Example 1:Input: k = 3, n = 7Output:[[1,2,4]] Example 2:Input: k = 3, n = 9Output:[[1,2,6], [1,3,5], [2,3,4]]https://leetcode.com/problems/co...

[LeetCode] 55. Jump Game Java【代码】【图】

题目: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.Determine if you are able to reach the last index.For example:A = [2,3,1,1,4], return true.A = [3,2,1,0,4], return false.题意及分析:根据题目要求,数组里的每个元素表示从该位置可以跳出的最远距离,要求问从第一个元素...

175. Combine Two Tables【LeetCode】-LEFT JON 和RIGHT JOIN,两张表关联查询-java -sql入门【代码】

Table: Person+-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId is the primary key column for this table. Table: Address+-------------+---------+ | Column Name | Type | +-------------+---------+ | AddressId | int | | PersonId | int | | City ...