Leetcode-242 有效的字母异位词
给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。demo01输入: s = "anagram", t = "nagaram"输出: truedemo02输入: s = "rat", t = "car"输出: false说明:你可以假设字符串只包含小写字母。题解关键词:map首先判断两个字符串长度是否相等,不相等则直接返回 false遍历串s为map赋值,组成字母...
2021-07-23C++实现LeetCode(22.生成括号)
[LeetCode] 22. Generate Parentheses 生成括号Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:["((()))","(()())","(())()","()(())","()()()"]这道题给定一个数字n,让生成共有n个括号的所有...
2022-02-02C++实现LeetCode(228.总结区间)
[LeetCode] 228.Summary Ranges 总结区间Given a sorted integer array without duplicates, return the summary of its ranges.Example 1:Input: [0,1,2,4,5,7]Output: ["0->2","4->5","7"]Explanation: 0,1,2 form a continuous range; 4,5 form a continuous range.Example 2:...
2022-02-01C++实现LeetCode(27.移除元素)
[LeetCode] 27. Remove Element 移除元素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) ext...
2022-02-02C++实现LeetCode(72.编辑距离)
[LeetCode] 72. Edit Distance 编辑距离Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a characterDelete a characterReplace a characterExampl...
2022-02-02C++实现LeetCode(207.课程清单)
[LeetCode] 207. Course Schedule 课程清单There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]Given the total...
2022-02-01C++实现LeetCode(62.不同的路径)
[LeetCode] 62. Unique Paths 不同的路径A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the ...
2022-02-02C++实现LeetCode(24.成对交换节点)
[LeetCode] 24. Swap Nodes in Pairs 成对交换节点Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list's nodes, only nodes itself may be changed.Example:Given1->2->3->4, you should return the list as2->1->...
2022-02-02C++实现LeetCode(200.岛屿的数量)
[LeetCode] 200. Number of Islands 岛屿的数量Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges o...
2022-02-02C++实现LeetCode(92.倒置链表之二)
[LeetCode] 92. Reverse Linked List II 倒置链表之二Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5->NULL很奇怪为何没有倒置链表之一,就来了这个倒置链表之二,不过猜也能猜得到之一就是单纯的倒...
2022-01-17Leetcode 242, 关于数组递增和遍历的一点问题
public class Solution {public boolean isAnagram(String s, String t) { if(s.equals(t)) return true;if(s==null||t==null||s.length()!=t.length()) return false;int[] num=new int[26];for(int i=0;i<s.length();i++){ num[s.charAt(i)-'a']++; num[t.charA...
2021-06-11C++实现LeetCode(692.前K个高频词)
[LeetCode] 692.Top K Frequent Words 前K个高频词Given a non-empty list of words, return the k most frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical...
2022-02-01C++实现LeetCode(52.N皇后问题之二)
[LeetCode] 52. N-Queens II N皇后问题之二The n-queens puzzle is the problem of placing nqueens on an n×n chessboard such that no two queens attack each other.Given an integer n, return the number of distinct solutions to the n-queens puzzle.Example:Input: 4Output...
2022-02-02C++实现LeetCode(126.词语阶梯之二)
[LeetCode] 126. Word Ladder II 词语阶梯之二Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a timeEach transformed word must...
2022-02-02C++实现LeetCode(210.课程清单之二)
[LeetCode] 210. Course Schedule II 课程清单之二There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]Given the ...
2022-02-01Pipes实现LeetCode(192.单词频率)
[LeetCode] 192.Word Frequency 单词频率Write a bash script to calculate the frequency of each word in a text file words.txt.For simplicity sake, you may assume:words.txt contains only lowercase characters and space ' ' characters.Each word must consist of lower...
2022-02-01C++实现LeetCode(122.买股票的最佳时间之二)
[LeetCode] 122.Best Time to Buy and Sell Stock II 买股票的最佳时间之二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 (ie, buy on...
2022-02-02C++实现LeetCode(21.混合插入有序链表)
[LeetCode] 21. Merge Two Sorted Lists 混合插入有序链表Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1->1->2->3->4->4这道混合插入有序链表和我之前...
2022-02-02【leetcode】221. 最大正方形 动态规划法
在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积。示例:输入:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0输出: 4动态规划法分析:我们用 dp(i,j)dp(i, j)dp(i,j) 表示以 (i,j)(i, j)(i,j) 为右下角,且只包含 111 的正方形的边长最大值。如果我们能计算出所有 dp(i,j)dp(i, j)dp(i,j) 的值,那么其中...
2020-08-08C++实现LeetCode(201.数字范围位相与)
[LeetCode] 201.Bitwise AND of Numbers Range 数字范围位相与Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7], you should return 4.Credits:Special thanks to @amrs...
2022-02-01C++实现LeetCode(86.划分链表)
[LeetCode] 86.Partition List 划分链表Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of the two partitions.For exa...
2022-02-02C++实现LeetCode(61.旋转链表)
[LeetCode] 61. Rotate List 旋转链表Given the head of a linked list, rotate the list to the right by k places.Example 1:Input: head = [1,2,3,4,5], k = 2Output: [4,5,1,2,3]Example 2:Input: head = [0,1,2], k = 4Output: [2,0,1]Constraints:The number of nodes in th...
2022-02-02C++实现LeetCode(12.整数转化成罗马数字)
[LeetCode] 12. Integer to Roman 整数转化成罗马数字Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...
2022-01-16Leetcode 206 链表反转 java解法求解释
Leetcode 206 反转链表的一道题,java做的,java萌新看懵逼了,求解释!public ListNode reverseList(ListNode head) {}1.这一行代码是什么意思?在solution类里调用listnode类并且新写了reverselist方法?2.注释里的ListNode类中 next是什么类型的变量?3.ListNode(int){val = x}在java里叫什么?静态方法么?作用是什么?4.reverselist...
2021-06-25C++实现LeetCode(152.求最大子数组乘积)
[LeetCode] 152. Maximum Product Subarray 求最大子数组乘积Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [2,3] has the largest...
2022-02-01