![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 51
羊城迷鹿
你相信魔法吗?
展开
-
SQL专题
文章目录寻找大国可回收且低脂的产品寻找用户推荐人从不订购的客户游戏玩法分析I寻找大国OR条件判断select name, population, area from world where area >= 3000000 or population >= 25000000;可回收且低脂的产品AND条件判断,字符串判断select product_id from Products where low_fats = 'Y' and recyclable = 'Y';寻找用户原创 2022-04-06 00:18:00 · 759 阅读 · 0 评论 -
图相关算法
文章目录课程表课程表本质上是判断有向图是否是无环的,可以用拓扑排序来求解class Solution {public: bool canFinish(int numCourses, vector<vector<int>>& prerequisites) { //每一个节点对应被指向的节点集合 unordered_map <int, unordered_set<int>> in_nodes;原创 2022-04-02 21:17:24 · 606 阅读 · 0 评论 -
LeecCode剑指offer集锦
剑指 Offer 09. 用两个栈实现队列题目很简单,在纸上画一下就懂了,不过可以复习一下类和STL的知识。class CQueue {public: stack<int> s1; stack<int> s2; CQueue() { } void appendTail(int value) { s1.push(value); } int deleteHead() { in原创 2022-01-26 10:54:17 · 580 阅读 · 0 评论 -
剑指 Offer 11: 旋转数组的最小数字
最简单的遍历思路其实相当于只二分一次,如果左半部分偏大就从右往左遍历,反之从左往右。class Solution {public: int minArray(vector<int>& numbers) { int left = 0, right = numbers.size()-1; if (numbers[left] <= numbers[(left+right)/2]) { for (;right >原创 2022-01-25 22:42:40 · 229 阅读 · 0 评论 -
LeetCode 53: 最大子序和
动态规划解法一class Solution {public: int maxSubArray(vector<int>& nums) { int s = nums.size(); if (s == 1) { return nums[0]; } int mmax = nums[0]; for (int i = 1; i < s; i++) { nu原创 2022-01-25 12:59:27 · 161 阅读 · 0 评论 -
LeetCode 206:反转链表
递归解法思路还是比较简单的,就是通过递归得到尾结点,作为翻转后的头结点返回,同时在每一步函数返回之后把指针的方向反过来。要注意的一点是,由于原来的头结点变成了尾结点,要把它对应的next设为null,如果忽视了就会报错。class Solution {public: ListNode* reverseList(ListNode* head) { if (head == nullptr || head -> next == nullptr) { re原创 2022-01-25 11:33:41 · 129 阅读 · 0 评论 -
用二分法求解两数之和问题
#include <vector>#include <algorithm>class Solution {public: int binary_search(vector<int>& v, int start, int end, const int target) { if (target < v[start] || target ...原创 2019-08-10 14:46:45 · 607 阅读 · 0 评论 -
LeetCode: Add Two Numbers
链表感觉忘光了。。。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */#include <cmath>class S...原创 2019-07-12 14:47:58 · 80 阅读 · 0 评论 -
Roman to Integer
无脑mapclass Solution {public: int romanToInt(string s) { std::map<string, int> M; M["I"] = 1; M["V"] = 5; M["X"] = 10; M["L"] = 50; M["C"] = ...原创 2019-07-14 19:38:18 · 76 阅读 · 0 评论 -
LeetCode题解:Reverse Integer
#include <iostream>using namespace std;class Solution {public: int reverse(int x) { int result = 0; while(x) {// 把10*result > INT_MAX转换成下面这种形式 if (re...原创 2019-07-14 13:26:10 · 171 阅读 · 0 评论 -
Maximum Subarray
class Solution {public: int maxSubArray(vector<int>& nums) { int max = nums[0]; for (int i = 1; i < nums.size(); i++) { if (nums[i-1] > 0) { num...原创 2019-07-14 00:38:01 · 146 阅读 · 0 评论 -
3Sum Closest解题报告
题目Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input w...原创 2018-09-10 09:08:20 · 284 阅读 · 0 评论 -
First Missing Positive解题报告
其实看到这种hard类型的题目,还是有点紧张的,但有惊无险,一次就过了。题目描述Given an unsorted integer array, find the smallest missing positive integer.大意就是说,给你一堆毫无规则的正数,你要给出其中不包含的正数里面最小的那一个。额外建立数组法一开始我其实想到了那个查找第K大元素的典型问题,但是...原创 2018-09-16 19:52:59 · 221 阅读 · 0 评论 -
LeetCode题解:Substring with Concatenation of All Words
题目要求You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once...原创 2018-09-23 17:17:57 · 141 阅读 · 0 评论 -
Longest Valid Parentheses题解
题目要求Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest...原创 2018-09-27 22:04:48 · 215 阅读 · 0 评论 -
ValidNumber 题解
题目要求这个题目很简单,就是判断输入的字符串是不是合法的,比如说:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true" -90e3 " => true" 1e" =>原创 2018-10-13 00:40:25 · 179 阅读 · 0 评论 -
一道小学数学题:ZigZag Conversion
题目描述The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S...原创 2018-10-06 19:31:07 · 381 阅读 · 0 评论 -
LeetCode题解:Minimum Height Trees
题目要求For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called...原创 2018-10-19 19:51:14 · 155 阅读 · 0 评论 -
LeetCode题解:longest-increasing-subsequence(最长递增子序列)
题目描述Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], the length is 4. Note:There may be more than one result, it is only necessary...原创 2018-10-25 21:22:56 · 842 阅读 · 0 评论 -
Leetcode题解:十几行代码计算编辑距离
题目要求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 ...原创 2018-11-01 19:31:26 · 167 阅读 · 0 评论 -
LeetCode题解:Interleaving String的几种思路
题目要求Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.Example 1:Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"Output: trueExample 2:Input: s1 = "aabcc原创 2018-11-08 00:35:55 · 202 阅读 · 0 评论 -
Leetcode题解:用字符串快速解决Create Maximum Number问题
问题描述Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the digits from the ...原创 2018-11-20 22:24:17 · 198 阅读 · 0 评论 -
Leetcode题解:Scramble String
题目要求Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ ...原创 2018-11-17 23:45:16 · 165 阅读 · 0 评论 -
LeetCode题解:Dungeon Game——论如何让王子救出公主
题目(好久没看见这么有趣的了)The demons had captured the princess § and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was...原创 2018-11-29 22:04:52 · 1281 阅读 · 0 评论 -
LeetCode题解:Best Time to Buy and Sell Stock(致富有望???)
题目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 at most two transactions.Note: You may not ...原创 2018-12-05 10:58:59 · 285 阅读 · 0 评论 -
使用多种贪心和模拟退火算法求解Capacitated Facility Location Problem问题
文章目录题目描述数据集文件结构题目描述Suppose there are n facilities and m customers. We wish to choose:(1) which of the n facilities to open(2) the assignment of customers to facilitiesThe objective is to mini...原创 2018-12-21 19:59:54 · 641 阅读 · 0 评论 -
Median of Two Sorted Arrays
so easy,只要按序遍历到总长度的一半就好,不是很懂官网给一堆看不懂的公式。。。#include <vector>class Solution {public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { int ...原创 2019-07-12 23:06:21 · 72 阅读 · 0 评论 -
Longest Palindromic Substring(最长回文串)
class Solution {public: string longestPalindrome(string s) { //M[i][j]代表从i到j是否是一个回文串 int length = s.size(); if (length == 0) { return ""; } int M[len...原创 2019-07-13 17:26:56 · 92 阅读 · 0 评论 -
一步步改进Container With Most Water解法
题目描述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). F...原创 2018-09-06 11:08:56 · 161 阅读 · 0 评论