
oj-----LeetCode
oj
PX-C
以学好IT技术为目的。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
3. 无重复字符的最长子串
题意:解:双指针c++class Solution {public: int lengthOfLongestSubstring(string s) { unordered_map<char,int>mp; int maxn=0; for(int i=0,j=0;i<s.size();i++){ mp[s[i]]++; while(j<i&&mp[s[i]原创 2020-07-30 13:58:42 · 122 阅读 · 0 评论 -
2. 两数相加
题意:解:模拟链表+模拟十进制加法/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) {原创 2020-07-30 13:30:31 · 145 阅读 · 0 评论 -
1. 两数之和
题意:亲测O(n^2)可过可以hash一下O(n)过class Solution { public int[] twoSum(int[] nums, int target) { Map<Integer,Integer>mp=new HashMap<Integer,Integer>(); int n=nums.length; for(int i=0;i<n;i++){ if(mp.contai原创 2020-07-30 13:10:09 · 141 阅读 · 0 评论 -
5435. 并行课程 II (状态压缩)
int dp[1<<15];//dp[state] 上完状态为state的课程需要多少学期int chk[20];//表示课程i所需要先修课程的掩码class Solution {public: void dfs(int x,int m,int k,int v,int sta,vector<int>&cc) { if(m-x<k) return; if(k==0||x>=m){ ...原创 2020-07-30 13:04:56 · 230 阅读 · 0 评论 -
1438. 绝对差不超过限制的最长连续子数组(双指针)
注意rbegin() 是最后一个数据,而end()是最后一个数据的后一个 rend()是第一个的前一个数据这题应该是从最长连续不重复子序列改编过来的,但是做法是一样的class Solution {public: int longestSubarray(vector<int>& nums, int limit) { ...原创 2020-07-30 13:05:44 · 129 阅读 · 0 评论 -
1425. 带限制的子序列和(dp+单调队列进行优化)
class Solution {public: int constrainedSubsetSum(vector<int>& nums, int k) { vector<int>dp(nums.size(),0); dp[0]=nums[0]; int ans=dp[0]; ...原创 2020-07-30 13:06:03 · 165 阅读 · 0 评论 -
1434. 每个人戴不同帽子的方案数(状态压缩)
一般是把某一维数少的进行状态压缩题目链接const int mod=1e9+7;int dp[45][1<<10];/*dp[i][bits] 前i顶帽子确定了归属,人戴帽子的状态为bits的方案数dp[i][bits]->dp[i+1][n_bits]*/class Solution {public: int numberWays...原创 2020-07-30 13:06:27 · 173 阅读 · 0 评论