随笔分类 -  手敲代码

摘要:原题: 题目意思大致是这样 输入的NC 如4 说明输入的这个addbabac 有abcd四个不同字符 输入的N 如 3 是指子串长度 输入的s 如daababac是主串 我们要找主串中不同的连续子串数目 子串长度必须为N 如daababac 有 这五个不同连续子串 这样一看 好像这个NC没啥用 我们 阅读全文
posted @ 2022-01-18 15:17 然终酒肆 阅读(29) 评论(0) 推荐(0) 编辑
摘要:#include <bits/stdc++.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ boo 阅读全文
posted @ 2021-01-28 21:24 然终酒肆 阅读(77) 评论(0) 推荐(0) 编辑
摘要:c++: class Solution { public: string addBinary(string a, string b) { if(a == "") return b; if(b == "") return a; int i = a.size() - 1; int j = b.size( 阅读全文
posted @ 2021-01-25 23:44 然终酒肆 阅读(63) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<int> plusOne(vector<int>& digits) { int len = digits.size(); for(int i = len -1;i>=0;i--) { if(digits[i] != 9) { digit 阅读全文
posted @ 2021-01-25 22:37 然终酒肆 阅读(81) 评论(0) 推荐(0) 编辑
摘要:出题人语死早,并没有叙述清楚 值得注意的是,“abc ”这个字符串是有单词存在的 所以从尾部判断的时候还要再看一下前边 class Solution { public: int lengthOfLastWord(string s) { int len = s.size(); int rear = l 阅读全文
posted @ 2021-01-25 21:56 然终酒肆 阅读(38) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int maxSubArray(vector<int>& nums) { int res = nums[0]; int sum = 0; for( int num : nums ) { if(sum > 0) sum+=num; else sum = 阅读全文
posted @ 2021-01-25 21:26 然终酒肆 阅读(51) 评论(0) 推荐(0) 编辑
摘要:迭代: class Solution { public: string countAndSay(int n) { string ans ="1"; n-=1; int s_index;//开始的索引 string temp; while(n--) { temp = ""; s_index =0; f 阅读全文
posted @ 2021-01-25 21:03 然终酒肆 阅读(50) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int removeDuplicates(vector<int>& nums) { int i = 0; int len = nums.size(); if(len==0) return 0; for(int j =1;j<len;j++ ) { i 阅读全文
posted @ 2021-01-22 23:42 然终酒肆 阅读(66) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : 阅读全文
posted @ 2021-01-22 23:25 然终酒肆 阅读(51) 评论(0) 推荐(0) 编辑
摘要:模拟面试的时候,遇到了这种题 确实是简单至极的题目 但是我 忘了栈用stl怎么写。又懒得用结构体写栈。 自己用vector造了一个栈。。。 我猜压根没像我这么写的 就很快乐 class Solution { public: bool isValid(string s) { if(s == "") r 阅读全文
posted @ 2021-01-21 23:32 然终酒肆 阅读(45) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: string longestCommonPrefix(vector<string>& strs) { if(!strs.size()) return ""; else if(strs.size() == 1 ) return strs[0]; els 阅读全文
posted @ 2021-01-21 22:23 然终酒肆 阅读(56) 评论(0) 推荐(0) 编辑
摘要:class Solution { public boolean isPalindrome(int x) { if(x < 0) return false; int cur = 0; int num = x; while(num != 0) { cur = cur * 10 + num % 10; n 阅读全文
posted @ 2021-01-18 14:52 然终酒肆 阅读(57) 评论(0) 推荐(0) 编辑
摘要:这是一道再水不过的题。但是这道题其实会引起一些思考的 这道题解法一定很多 初见这道题时,大多数人想的思路应该就是直接暴力 数字转字符串。但是这样未免太低级了。 在高级点就是,反转其实可以用栈。 一步一步用vector 推进去 或者用栈推进去然后输出就行了 中间要判断是否溢出,还有0和负号的一些处理 阅读全文
posted @ 2021-01-18 14:38 然终酒肆 阅读(64) 评论(0) 推荐(0) 编辑
摘要:百忙之中刷一道算法题 一眼看出来就是并查集了 class Solution { public: int f[20000+10]; int find(int x) { if(f[x] != x) f[x] = find(f[x]); return f[x]; } int removeStones(ve 阅读全文
posted @ 2021-01-15 19:01 然终酒肆 阅读(84) 评论(0) 推荐(0) 编辑
摘要:#include<algorithm> #include<map> #include<vector> #include<string> #include<iostream> #include<stack> using namespace std; #define max 203 #define in 阅读全文
posted @ 2021-01-10 16:26 然终酒肆 阅读(72) 评论(0) 推荐(0) 编辑
摘要:有关ArrayList参见菜鸟教程 https://www.runoob.com/java/java-arraylist.html 代码不敲了 很简单 这个也是 太水了 不敲了 阅读全文
posted @ 2020-12-20 12:09 然终酒肆 阅读(73) 评论(0) 推荐(0) 编辑
摘要:没空敲了 代码是别人的轮子 稍微改了改 把单链表全实现了 package Test; public class Linked <T>{ private class Node{ private T t; private Node next; public Node(T t,Node next){ th 阅读全文
posted @ 2020-12-20 10:30 然终酒肆 阅读(71) 评论(0) 推荐(0) 编辑
摘要:package Test; public class test0 { static final int SLOW = 1;//三个名为SLOW,MEDIUM,FAST而值为1,2,3的常量,表示风扇的速度。 static final int MEDIUM = 2; static final int 阅读全文
posted @ 2020-12-20 10:16 然终酒肆 阅读(102) 评论(0) 推荐(0) 编辑
摘要:package homwk; import java.util.Scanner; public class hmwk7 { public static boolean judge(int[][] b){ for(int i=0;i<b.length;i++){ for(int j=0;j<b[i]. 阅读全文
posted @ 2020-12-20 10:09 然终酒肆 阅读(69) 评论(0) 推荐(0) 编辑
摘要:复习bfs 这题我们用bfs 做 class Solution { public: int numSquares(int n) { queue <int> q; vector <int> dist(n+1,INT_MAX); q.push(0); dist[0] = 0; while(q.size( 阅读全文
posted @ 2020-12-16 18:51 然终酒肆 阅读(72) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示