首页
学习
活动
专区
工具
TVP
发布

算法修养

专栏成员
674
文章
399642
阅读量
49
订阅数
LeetCode 82. Remove Duplicates from Sorted List II
题目 c++ /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* deleteDuplicates(ListNode* head) {
ShenduCC
2019-11-14
2480
LeetCode 83. Remove Duplicates from Sorted List
题目 c++ /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* deleteDuplicates(ListNode* head) {
ShenduCC
2019-11-14
2630
LeetCode 61. Rotate List
题目 c++ /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* rotateRight(ListNode* head, int k) { if(he
ShenduCC
2019-09-16
5030
LeetCode 60. Permutation Sequence
康拓展开其实就是表示一个连续序列,其实也不用连续,给定一个序列,可以很快速的按照字典序,列出所有序列。给出特定序列,快速告诉你它是按照字典序排序是第几个,给出排名,快速输出序列
ShenduCC
2019-09-10
3080
使用位运算实现int32位 整数的加减乘除
我觉得异或操作和与操作完全就是实现加法的。 异或就是相同位相加最后留下的结果,而与就是相同位相加是否进1的结果。
ShenduCC
2019-08-26
1.3K0
LeetCode 43 Multiply Strings
题目 用字符串模拟两数相乘。 在纸上模拟一下小学时学的算术乘法,就知道怎么做了。 c++ class Solution { public: int ans[10005]; string multiply(string num1, string num2) { if(num1=="0"||num2=="0") return "0"; int pos=0; int start=0;
ShenduCC
2019-08-20
5380
LeetCode 42. Trapping Rain Water
题目 1A c++ O(n^2) class Solution { public: int trap(vector<int>& height) { int ans=0; for(int i=1;i<height.size();i++) { if(height[i]>height[i-1]) { int pos=0;
ShenduCC
2019-08-16
3860
LeetCode 38.Count and Say
c++ ``` class Solution { public: string a[31]; string countAndSay(int n) {
ShenduCC
2019-08-06
3270
LeetCode 37. Sudoku Solver
题目 c++ DFS ,代码写的又臭又长,Faster than 85.33% class Solution { public: set<int> a[10][10]; set<pair<int,int>> e; int b[10][10]; int c[10][10]; int judge(int i,int j,int x) { for(int k=0;k<9;k++) { if(k==j) cont
ShenduCC
2019-08-06
2960
LeetCode 33 Search in Rotated Sorted Array
题目 c++ 二分 class Solution { public: int search(vector<int>& nums, int target) { if(nums.size()==0) return -1; int start=0; int end = nums.size()-1; int ans=-1; while(start<end)
ShenduCC
2019-07-24
3710
LeetCode 31. Next Permutation
题目 c++ class Solution { public: void nextPermutation(vector<int>& nums) { int tag=0; int z=-1; for(int i=nums.size()-1;i>=0;i--) { if(i!=0&&nums[i]>nums[i-1]) { z=i-1;
ShenduCC
2019-07-18
2930
LeetCode 27 Remove Element
题目 c++ class Solution { public: int removeElement(vector<int>& nums, int val) { int ans = nums.size(); int i=0; while(i<ans) { if(nums[i]==val) { int j=i+1;
ShenduCC
2019-07-15
5450
LeetCode 19. Remove Nth Node From End of List
题目 c++ /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) {
ShenduCC
2019-07-01
2970
LeetCode 14 Longest Common Prefix
题目 c++ class Solution { public: string longestCommonPrefix(vector<string>& strs) { if(strs.size()==0) return ""; int i=0; string ans=""; while(true) { if(i==strs[0].length())
ShenduCC
2019-06-24
5660
LeetCode 13 Roman to Integer
题目 c++ class Solution { public: int v[7]={1,5,10,50,100,500,1000}; char s2[7]={'I','V','X','L','C','D','M'}; map<char,int>m; int romanToInt(string s) { int j=0; for(int i=0;i<7;i++) { m[s2[i]]=v[i];
ShenduCC
2019-06-24
2370
LeetCode 9 Palindrome Number
题目 c++ class Solution { public: int a[100005]; bool isPalindrome(int x) { if(x<0) return false; int pos=0; while(x) { a[pos++]=x%10; x/=10; }
ShenduCC
2019-06-18
3270
LeetCode 8 String to Integer (atoi)
题目 c++ 多注意注意 class Solution { public: int myAtoi(string str) { int len = str.length(); int tag=0; int tag2=0; char tag3='x'; string num=""; for(int i=0;i<len;i++) { if(str[i]!
ShenduCC
2019-06-16
2930
LeetCode 7 Reverse Integer
题目 c++ class Solution { public: int reverse(int x) { long long int ans=0; int tag=0; while(x) { long long int y =x%10; x/=10; if(y==0&&tag==0) continue;
ShenduCC
2019-06-05
3690
LeetCode 3 Longest Substring Without Repeating Characters
题目 c++ class Solution { public: map<char,int> m; int a[100005]; int lengthOfLongestSubstring(string s) { int len = s.length(); if(len==0) return 0; a[0]=1; m[s[0]]=1; int mm=1;
ShenduCC
2019-06-03
2500
LeetCode 152 Maximum Product Subarray
题目 思路 维护两个数组,一个是a[i] 表示以i为结尾的子序列乘积的最大值 一个是b[i] 表示以i为结尾的子序列乘积的最小值 然后就是动态规划的思想。 c++ class Solution { public: int s[1000005]; int a[1000005]; int b[1000005]; int maxProduct(vector<int>& nums) { a[0]=nums[0]; b[0]=nums[0]
ShenduCC
2019-05-15
2940
点击加载更多
社区活动
【纪录片】中国数据库前世今生
穿越半个世纪,探寻中国数据库50年的发展历程
Python精品学习库
代码在线跑,知识轻松学
博客搬家 | 分享价值百万资源包
自行/邀约他人一键搬运博客,速成社区影响力并领取好礼
技术创作特训营·精选知识专栏
往期视频·千货材料·成员作品 最新动态
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档