go 切片的 插入、删除
package main import (
"fmt"
) func InsertSpringSliceCopy(slice, insertion []string, index int) []string { result :=make([]string, len(slice)+len(insertion))
at := copy(result, slice[:index])
at += copy(result[at:], insertion)
copy(result[at:], slice[index:])
return result
} func InsertSpringSlice(slice, insertion []string, index int) []string {
return append(slice[:index], append(insertion, slice[index:]...)...) } func RemoveSpringSliceCopy(slice []string, start,end int) []string {
result := make([]string, len(slice)-(end-start))
at :=copy(result, slice[:start])
copy(result[at:], slice[end:])
return result
} func RemoveSpringSlice(slice []string, start, end int) []string {
return append(slice[:start], slice[end:]...)
} func main() {
s := []string{"C", "H", "A", "O"}
x := InsertSpringSliceCopy(s, []string{"a", "b", "c"}, )
fmt.Println(x) w := []string {"C", "H", "E", "N"}
ww :=InsertSpringSlice(w, []string{"c", "h", "a", "o"}, len(w))
fmt.Println(ww) d := []string {"a", "b", "c", "d", "e", "f"}
dd := RemoveSpringSliceCopy(d, , )
fmt.Println(dd) d2 := []string {"A", "B", "C", "D", "E", "F", "G"}
dd2 := RemoveSpringSlice(d2, , )
fmt.Println(dd2)
}
go 切片的 插入、删除的更多相关文章
- [LeetCode] Insert Delete GetRandom O(1) - Duplicates allowed 常数时间内插入删除和获得随机数 - 允许重复
Design a data structure that supports all following operations in average O(1) time. Note: Duplicate ...
- [LeetCode] Insert Delete GetRandom O(1) 常数时间内插入删除和获得随机数
Design a data structure that supports all following operations in average O(1) time. insert(val): In ...
- python Trie树和双数组TRIE树的实现. 拥有3个功能:插入,删除,给前缀智能找到所有能匹配的单词
#coding=utf- #字典嵌套牛逼,别人写的,这样每一层非常多的东西,搜索就快了,树高26.所以整体搜索一个不关多大的单词表 #还是O(). ''' Python 字典 setdefault() ...
- leveldb源码分析--插入删除流程
由于网络上对leveldb的分析文章都比较丰富,一些基础概念和模型都介绍得比较多,所以本人就不再对这些概念以专门的篇幅进行介绍,本文主要以代码流程注释的方式. 首先我们从db的插入和删除开始以对整个体 ...
- 洛谷 P2042 [NOI2005]维护数列-Splay(插入 删除 修改 翻转 求和 最大的子序列)
因为要讲座,随便写一下,等讲完有时间好好写一篇splay的博客. 先直接上题目然后贴代码,具体讲解都写代码里了. 参考的博客等的链接都贴代码里了,有空再好好写. P2042 [NOI2005]维护数列 ...
- jQery实现插入删除信息
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- [LeetCode] 381. Insert Delete GetRandom O(1) - Duplicates allowed 常数时间内插入删除和获得随机数 - 允许重复
Design a data structure that supports all following operations in average O(1) time. Note: Duplicate ...
- [LeetCode] 380. Insert Delete GetRandom O(1) 常数时间内插入删除和获得随机数
Design a data structure that supports all following operations in average O(1) time. insert(val): In ...
- Splay的基本操作(插入/删除,查询)
Splay的基本操作(插入/删除,查询) 概述 这是一棵二叉查找树 让频繁访问的节点尽量靠近根 将查询,插入等操作的点"旋转"至根 树的高度均摊为$log_n$ 变量 int ro ...
- jQuery---jq操作标签文本(html(),text()),jq操作文档标签(插入,删除,修改),克隆,,jq操作属性,jq操作class属性,jq操作表单value,jq操作css,jq操作盒子(重要),jq操作滚动条
jQuery---jq操作标签文本(html(),text()),jq操作文档标签(插入,删除,修改),克隆,,jq操作属性,jq操作class属性,jq操作表单value,jq操作css,jq操作盒 ...
随机推荐
- nginx之编译安装
一.认识nginx 常用的web服务有Apache.IIS(windows系统).Lighttpd.Tomcat.Nginx等.Nginx是一个开源的,支持高性能.高并发的www服务和代理服务软件.它 ...
- 【bzoj4520】 Cqoi2016—K远点对
http://www.lydsy.com/JudgeOnline/problem.php?id=4520 (题目链接) 题意 求平面内第K远点对的距离. Solution 左转题解:jump 细节 刚 ...
- phpredis用法笔记
项目中用到redis集群, 发现phpredis对集群,分布式是有支持的.翻译下相关资料备用. redis扩展地址:https://github.com/phpredis/phpredis, 看到如下 ...
- [THUSC 2016] 补退选 (Trie树)
link $solution:$ $Trie$树很显然吧,那么如何去处理每次询问.对于$Trie$树的每个节点放一个$vector$表示其若有$v$个人的最小时间. #include<iostr ...
- 在ubuntu下安装opencv
每次学习一个新的东西,最让气恼的也许就是库,软件之类的东西了把.本来以为再ubuntu虚拟机上照着网上的教程一步步做肯定一下子就弄好了,结果发现好多教程都有好多的坑,有些地方他们少一步你也不知道,有些 ...
- Python【网络编程】内置模块urllib
from urllib import request,parseurl = 'http://www.nnzhp.cn'req = request.urlopen(url) #打开一个url,发get请 ...
- Python入门 语法
Python入门 语法 语言介绍 对象,类型,值 编码规范 https://www.python.org/dev/peps/pep-0008/ 一.语言介绍 编程语言: 机器语言,汇编语言,高级语言 ...
- 「Vue」v-html生成的图片大小无法调整的解决办法
问题: v-html生成的图片调整大小属性没用<div class="content" v-html="pdinfo.content"></d ...
- 同一个局域网中用Windows自己的远程桌面远程局域网中的其他PC
同一个局域网中用Windows自己的远程桌面远程局域网中的其他PC... ===================== 建立Windows远程访问的前提: 1.访问PC和被访问的PC在同一个局域网中 2 ...
- P4711 「化学」相对分子质量
P4711 「化学」相对分子质量 给你一个字符串让你输出相对分子质量(弱智字符串模拟) 我比赛tm调了两个半小时啊QAQ 希望以后能增加代码力吧,纪念挂代码 Code #include<iost ...