leet专题

Leet Code Medium 18 4Sum

http://tech-wonderland.net/blog/summary-of-ksum-problems.html

Leet Code Medium 15 3Sum

【题目】 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet

Leet Code 14 Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings 【算法思路】 1. 找最短的一个串,然后与其他串每个字符比较 public String longestCommonPrefix(String[] strs) {if(strs.length == 0)re

Leet Code 5 Longest Palindromic Substring

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 【算法思路】 1. 最简单的办法就是以

Leet Code 4 Median of Two Sorted Arrays

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 【算法思路】        搜了一下

uva 1509 - Leet(暴力)

题目链接:uva 1509 - Leet 题目大意:给出k,表示一个字符可以对应k给字符编码,给出字符串1,问时候有符合的编码可以生成字符串2. 解题思路:暴力枚举,对于每个碰到的字符记录对应的编码。

UVA 1509 Leet(暴力)

UVA 1509 Leet 题目链接 题意:给定一个字符串和一个字符串,第一个字符串字母可以映射1-k个字母,问第一个字符串能否表示成第二个字符串 思路:dfs暴力枚举即可 代码: #include <cstdio>#include <cstring>const int N = 305;int t, k, n, m, v[N], len[N];char a[60],

Leet code 179 最大数

解题思路 贪心算法 贪心算法就是走一步看一步 每一步都取当前位置的最优解 这题我们该如何贪呢? 我们先把int数组转换为string数组  以示例2为例 3 30 34 5 9 排序哪个在前哪个在后? 3 + 30  (330)>  30 +3 (303) 那么3就在前 30在后   该题的贪心规律就是 a+b >b+a  通过sort 算法可以排序  然后还有一个特列处理

Leet code 904 水果成篮

解题思路:滑动窗口 创建hash表记录水果的种类和数量  两个指针left 和 right 从数组起始位置开始滑动,right在循环内++ hash[fruits[right]]++  进窗口 然后判断 hash表中的种类是否大于2 一旦大于2就要想办法出窗口  出窗口需要将hash表中种类重回2种 这时候就要动用left指针 然后更新结果  代码如下 class Soluti

Leet code 三步问题

解题思路:动态规划 先观察 1级台阶 1种方法             2级台阶 2种方法             3级台阶 4种方法             4级台阶 7种方法              5级台阶 13种方法  可以看出规律 从3级台阶后 每级台阶需要从前三层台阶和相加 注意:后面值会过大  需要在相加之后就模运算1000000007 代码如下 class

Leet Code OJ 127. Word Ladder [Difficulty: Medium]-python

题目: 127. Word Ladder Medium Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that: Only on

Leet Code OJ 125. Valid Palindrome [Difficulty: Easy] -python

题目: 125. Valid Palindrome Easy Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty

Leet Code OJ 98. Validate Binary Search Tree [Difficulty: Medium] -python

题目: 98. Validate Binary Search Tree Medium Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only n

Leet Code OJ 88. Merge Sorted Array [Difficulty: Easy] -python

题目: 88. Merge Sorted Array Easy 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

Leet Code OJ 73. Set Matrix Zeroes [Difficulty: Medium] -python

题目 73. Set Matrix Zeroes Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place. Follow up: A straight forward solution using O(mn) space is probably a bad i

Leet Code OJ 70. Climbing Stairs [Difficulty: Easy] -python

爬楼梯问题: 70. Climbing Stairs Easy 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

Leet Code OJ 56. Merge Intervals [Difficulty: Medium] -Python

56. Merge Intervals 【Medium】 Given a collection of intervals, merge all overlapping intervals. Example 1: Input: intervals = [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation

Leet-code 869.重新排序得到 2 的幂

问题描述: 给定正整数 N ,我们按任何顺序(包括原始顺序)将数字重新排序,注意其前导数字不能为零。 如果我们可以通过上述方式得到 2 的幂,返回 true;否则,返回 false。 示例 1: 输入:1输出:true 示例 2: 输入:10输出:false 示例 3: 输入:16输出:true 示例 4: 输入:24输出:false 示例 5: 输入:46

Leet 350:两个数组的交集II

给你两个整数数组 nums1 和 nums2 ,请你以数组形式返回两数组的交集。返回结果中每个元素出现的次数,应与元素在两个数组中都出现的次数一致(如果出现次数不一致,则考虑取较小值)。可以不考虑输出结果的顺序。 示例 1: 输入:nums1 = [1,2,2,1], nums2 = [2,2]输出:[2,2] 示例 2: 输入:nums1 = [4,9,5], nums2 = [9,

一天一大 leet(转变数组后最接近目标值的数组和)难度:中等 DAY-14

20200614 题目(难度:中等): 给你一个整数数组 arr 和一个目标值 target ,请你返回一个整数 value ,使得将数组中所有大于 value 的值变成 value 后,数组的和最接近  target (最接近表示两者之差的绝对值最小)。 如果有多种使得和最接近 target 的方案,请你返回这些整数中的最小值。 请注意,答案不一定是 arr 中的数字。 示例