原文链接: https://kettycode.github.io/page/4/index.html
版权声明: 转载请注明出处.
位运算基础——不需要额外空间交换两个数
不用额外空间交换两个数
基础位运算
1 | &----与 |
简单交换算法
1 | void Swap(int& num1, int& num2){ |
原文链接: https://kettycode.github.io/page/4/index.html
版权声明: 转载请注明出处.
位运算基础——找出数组中唯一一个只有一个的数
简单模式:数组中只有一个数出现一次,其他均出现两次,请找出这个数。
1 | //原理:a ^ a = 0 a ^ 0 = a |
进阶模式:数组中只有一个数出现一次,其他均出现三次,请找出这个数。(题目来自力扣137)
例:
【1,2,3,2,4,4,3,4,2,3】
0001
0010
0011
0010
0100
0100
0011
0100
0010
0011
++++
0364
%%%%3
0001
1 | // |
算法改进
第i位(ai,bi)初始(00)连续经过三个零或三个1又变回(00)
(00)->(01)->(10)->(00)
| (ai,bi) | xi | 新(ai,bi) |
|---|---|---|
| 00 | 0 | 00 |
| 00 | 1 | 01 |
| 01 | 0 | 01 |
| 01 | 1 | 10 |
| 10 | 0 | 10 |
| 10 | 1 | 00 |
a = (~a & b & x) | (a & ~b & ~x)
b = ~a & (b ^ x)
最后结果:ai=0 ,bi=0/1,即返回b即可。
1 | int FindOnlySum(vector<int>& nums) { |
进一步改进–同时计算改为分步计算
因为bi计算更简单,所以我们先计算bi,再用新bi计算ai。
(00)->(01) => (00)->(01)->(01)
| (ai,bi) | xi | 新bi |
|---|---|---|
| 00 | 0 | 0 |
| 00 | 1 | 1 |
| 01 | 0 | 1 |
| 01 | 1 | 0 |
| 10 | 0 | 0 |
| 10 | 1 | 0 |
| (新ai,bi) | xi | 新ai |
|---|---|---|
| 00 | 0 | 0 |
| 01 | 1 | 0 |
| 01 | 0 | 0 |
| 00 | 1 | 1 |
| 10 | 0 | 1 |
| 10 | 1 | 0 |
b = ~a & (b ˆ x)
a = ~b & (a ˆ x)
1 | class Solution { |
原文链接: https://kettycode.github.io/page/4/index.html
版权声明: 转载请注明出处.
vue学习之路--基础知识
组合式vue3
1.reative,ref
1 | <script setup> |
2.Attrictive绑定 v-bind:id => :id
v-bind:id=”dynamicId” 可简写成 :id=”dynamicId”
1 | <script setup> |
3.事件监听 v-on:click => @click
v-on:click=”increment”> 简写成 @click=”increment”>
1 | <script setup> |
1 | <script setup> |
4.表单绑定 v-bind:id = “text” 和 v-on:input = “onInput” => v-model = “text”
v-bind 和 v-on 来在表单的输入元素上创建双向绑定,为了简化双向绑定,Vue 提供了一个 v-model 指令,它实际上是语法糖
1 |
|
1 | <input v-model="text"> |
5.条件渲染 v-if和v-else
1 | <h1 v-if="awesome">Vue is awesome!</h1> |
1 | <script setup> |
6.列表渲染 v-for
1 | <ul> |
1 | <script setup> |
7.计算属性
介绍一个新 API:computed()。它可以让我们创建一个计算属性 ref,这个 ref 会动态地根据其他响应式数据源来计算其 .value
1 | <script setup> |
原文链接: https://kettycode.github.io/page/4/index.html
版权声明: 转载请注明出处.
vue学习之路--其他知识
在script标签中写js代码,或者使用src引入js文件时,默认不能使用module形式,即不能使用import导入文件,但是我们可以再script标签上加上type=module属性来改变方式。
1 | //module.js |
1 | // index.html |
鼠标悬停效果
1 | <template> |
原文链接: https://kettycode.github.io/page/4/index.html
版权声明: 转载请注明出处.
如何使用 makedown 编写个人博客
1.标题
1 | 一级标题 |
2.字体
1 | *斜体文本* |
3.一些特殊线
1 | 分割线 |
4.脚注
1 | [^要注明的文本] |
创建脚注格式类似这样 ^bilibili。
5.列表
1 | * 第一项 |
6.区块
1 | >后加空格表示区块引用 |
7.代码
1 | 如果是段落上的一个函数或片段的代码可以用反引号把它包起来(`),例如: |
<c++
int main(){
return 0;
}
1 | int main(){ |
8.链接
1 | [链接名称](链接地址) |
以下是高级链接生成的结果:
这个链接用 1 作为网址变量 Google
这个链接用 bili 作为网址变量 B站
然后在文档的结尾为变量赋值(网址)
1: http://www.google.com/
bili: https://www.bilibili.com/
这个链接用 1 作为网址变量 Google
这个链接用 bili 作为网址变量 B站
然后在文档的结尾为变量赋值(网址)
9.图片
1 |  |
10.表格
1 | | 表头 | 表头 | |
11.其他
1 | 不在 Markdown 涵盖范围之内的标签,都可以直接在文档里面用 HTML 撰写。 |
参考资料:菜鸟教程https://www.runoob.com/markdown/md-tutorial.html
原文链接: https://kettycode.github.io/page/4/index.html
版权声明: 转载请注明出处.
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick Start
Create a new post
1 | $ hexo new "My New Post" |
More info: Writing
Run server
1 | $ hexo server |
More info: Server
Generate static files
1 | $ hexo generate |
More info: Generating
Deploy to remote sites
1 | $ hexo deploy |
More info: Deployment
原文链接: https://kettycode.github.io/page/4/index.html
版权声明: 转载请注明出处.