04 2023 档案

摘要:443: 双指针 短除法: while(num>0){ char[i]='0'+num%10; num/=10; } 要与之后的字符串进行比较,因为之后的字符串才是没有被改动过。所以:chars[i]==cahrs[i+1]因为与之后的字符串比较,所以要从0开始。 如果字符串出现不等,就将字符串记录 阅读全文
posted @ 2023-04-27 20:28 iu本u 阅读(20) 评论(0) 推荐(0) 编辑
摘要:算欧拉距离: 1.np.sqrt(np.sum(np.square(X[i]-centroids[j]))) 2.np.linalg.norm(X[i]-cemtroids[j]) 算数组中最小值的索引: np.argmin(distance) 3.取数组满足条件的索引 1 X[idx==1] 2 阅读全文
posted @ 2023-04-26 20:59 iu本u 阅读(19) 评论(0) 推荐(0) 编辑
摘要:1.vector<int>v(size) 2.vector<int>v(size,0) 3.vector<int>v={1,2,3,4} 4.int a={1,2,3,4} vector<int>v(a,a+2) 5.vector<int>v(v0) leetcode334:注意判定条件的顺序,开始 阅读全文
posted @ 2023-04-25 15:31 iu本u 阅读(13) 评论(0) 推荐(0) 编辑
摘要:151:reverse(a.begin(),a.end()); 翻转一个字符串a,翻转位置不计end s.erase(a.begin()+idx,a.end()); 删除最后的剩余不是单词的部分 String::move在string中push_back()是将数据复制一遍放进新的string这样造 阅读全文
posted @ 2023-04-22 19:56 iu本u 阅读(22) 评论(0) 推荐(0) 编辑
摘要:隐函数: auto isVowe=l[vowel="aoeiuAOEIU"s](char c){ return vowel.find(c)!=string::npos;} []捕获列表,写传入以外的参数,string::npos一般表示这个值不存在字符串中,即不存在的位置。【】在最后写入s表示字符串 阅读全文
posted @ 2023-04-19 19:52 iu本u 阅读(7) 评论(0) 推荐(0) 编辑
摘要:605.首尾的处理方式和中间的植法不同,在之前设置一个哨兵即prev=-1; if(i位置有树) if(prev<0){ 说明此时在开头植树,处理方式为位置数/2棵}else{ (位置数-2)/2 } if(prev<0)(总位置数+1)/2; else{尾部可以种树,处理方式为(i-prev-1) 阅读全文
posted @ 2023-04-18 20:55 iu本u 阅读(16) 评论(0) 推荐(0) 编辑
摘要:它是返回一个地址,返回地址的值要加*max_element(a.begin(),a,end()) 可以自己写方法 阅读全文
posted @ 2023-04-17 19:10 iu本u 阅读(34) 评论(0) 推荐(0) 编辑
摘要:string:string=“”; string.length() string.substr(0,i)从0位置开始截取i个字母付给新的字符串。 leetcode1071:1.str1+str2==str2+str1则必存在一个字符串是他们的公共字符串 2.如果两个字符串有公共字符串,则 一定他们的 阅读全文
posted @ 2023-04-16 20:08 iu本u 阅读(8) 评论(0) 推荐(0) 编辑
摘要:leeetcode733: &&判断条件是有顺序的。 深度优先是用递归,广度优先使用队列。 1.深度搜索 方向数组: dx={1,0,0,-1}; dy={0,1,-1,0}; 找到第一个要染色的方格,将它染色再递归染色其他方向的方格。 2.bfs 使用数据结构队列,满足染色条件入队,再将一层中的每 阅读全文
posted @ 2023-04-12 21:01 iu本u 阅读(17) 评论(0) 推荐(0) 编辑
摘要:235:关键在于从根节点开始找到分岔点,目标比根节点值都小在从左子树开始找,目标比当前节点都大在右子树开始找,除了这两种情况就是说明当前节点就是分岔点。 阅读全文
posted @ 2023-04-11 21:00 iu本u 阅读(16) 评论(0) 推荐(0) 编辑
摘要:LONG_MIN 为longlong的最小值 LONG_MAX为longlogn的最大值 二叉树的遍历:前序遍历、中序遍历、bfs遍历 前序和中序遍历:都用栈stack 中序遍历时升序(leetcode98) stack :stack.top() stack.push() bfs遍历:使用队列que 阅读全文
posted @ 2023-04-10 16:05 iu本u 阅读(10) 评论(0) 推荐(0) 编辑
摘要:对比704和278 704二分查找: 如果按照278方法做可鞥会跳过mid指针,因为在决定在左还是右查找时有三种情况,所以当查找中间位置时相等则返回。 278 在二分查找时分支只有两种情况,不会错过中间指针 阅读全文
posted @ 2023-04-07 17:17 iu本u 阅读(10) 评论(0) 推荐(0) 编辑
摘要:1.前序遍历法 数据结构:stack栈 操作: stack<Node*>st; st.top(); st.pop(); st.emplace(); 2.层次遍历法 数据结构:queue队列 操作: queue<Node*>q; q.front(); q.pop(); q.push(); 阅读全文
posted @ 2023-04-06 19:13 iu本u 阅读(2) 评论(0) 推荐(0) 编辑
摘要:589N叉树遍历 vector<Node*>children; for(auto &ch:children){} stack(Node*)st; Node* node=st.pop(); for(auto it=node->children.rbegin();it!=node.rend();it++ 阅读全文
posted @ 2023-04-06 15:14 iu本u 阅读(12) 评论(0) 推荐(0) 编辑
摘要:利用迭代器 for(auto it=a.begin();a!=a.end();it++){ cout<<*it<<endl; } for_each void func(double x){ cout<<x<<endl; } vector<double>a; for_each(a.begin(),a. 阅读全文
posted @ 2023-04-06 10:22 iu本u 阅读(14) 评论(0) 推荐(0) 编辑
摘要:876链表的中间节点 一个慢指针走一步,快指针走两步,注意返回终止条件 142环形链表 vector.insert(指针即某个位置) vector,count()计算是否已经存在某个元素 阅读全文
posted @ 2023-04-04 11:03 iu本u 阅读(12) 评论(0) 推荐(0) 编辑
摘要:392合并子序列 初始化: dp【i】[j]=i t[i]==j =dp[i+1][j] t[i]!=j 倒序记录 21递归算法 阅读全文
posted @ 2023-04-03 15:38 iu本u 阅读(5) 评论(0) 推荐(0) 编辑

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