随笔分类 - leetcode
摘要:题目描述 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 c
阅读全文
摘要:题目描述 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
阅读全文
摘要:题目描述 Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operat
阅读全文
摘要:题目描述 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The
阅读全文
摘要:题目描述 Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the
阅读全文
摘要:题目描述 Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: s = "anagram", t = "nagaram"Output: true Exa
阅读全文
摘要:题目描述 Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of th
阅读全文
摘要:题目描述 Given an integer matrix, find the length of the longest increasing path. From each cell, you can either move to four directions: left, right, up
阅读全文
摘要:题目描述 Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2. You have the following 3 operations pe
阅读全文
摘要:题目描述 Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'. '.' Matches any single character
阅读全文
摘要:一、 测试用例 测试用例一般需要考虑三种情况 1.常规值 2.边界值 3.空值 二、 解题思路 1.题目中说明自包含小写字母,一般应该用字典。 三、 做题技巧 1.交换 x = x ^ y // (1) y = x ^ y // (2) x = x ^ y // (3) 2.对2取余或除以2——右移
阅读全文
摘要:338. Counting Bits(计算小于n的各个数值对应的二进制1的个数) 思路:通过奇偶判断,if i是偶数,a[i]=a[i/2],if i是奇数,a[i]=a[i-1]+1。 class Solution { public: vector<int> countBits(int num)
阅读全文
摘要:数值查找 旋转数组问题 1.旋转数组,寻找给定值的具体位置,数值无重复;二分法,先寻找有序区间,不在有序区间,则在另外的区间:https://github.com/AntonioSu/leetcode/blob/master/problems/33.SearchinRotatedSortedArra
阅读全文
摘要:5. Longest Palindromic Substring 647. Palindromic Substrings 解法一:从中心一点向两边扩展,需要考虑中心为一点,中心为两点。 解法二:马拉车算法
阅读全文
摘要:二维数组V(i,j):前 i 个物品,背包容量 j,所能取得的最大价值 1) j<w(i) V(i,j)=V(i-1,j) //如果当前容量小于第i个物品的重量,则不会装入此物品,故而最大价值仍然为V(i-1,j) 2) j>=w(i) V(i,j)=max{ V(i-1,j),V(i-1,j-w(
阅读全文
摘要:首先需要明白 0-1 背包问题中的放置表格,见 “玩转算法面试 从真题到思维全面提升算法思维” 9-5 节,本题思路类似表格纵向为:只考虑第 [0 …,… index] 种硬币(物品)表格横向为:需要兑换的金额(背包容量)为 j表格内容为:在横向和纵向的条件下,最少的硬币(物品)数即:通过表格列举出
阅读全文