【无标题】
2023-12-13 09:36:05
Leetcode datastructures
- Python
(1) Dict:
a={}
a['x'] = 123
a.pop('x')
a.get('x',0)
del a['x']
a.items()
(2) set
a=set()
a=set([1,2,3])
a.add('x')
a.remove('x')
(3) collections.defaultdict
import collections.defaultdict as defaultdict
a=defaultdict(list)
a['x'].append(1)
(4)collections.deque:
a=deque()
a.append(1)
a.pop()
a.appendleft(1)
a.popleft()
(5) heapq
q=heapq.heapify(list)
heapq.heappush(q,1)
heapq.heappop(q)
q[0] # smallest, min-heap by default
heapq.nlargest(k,q) # q doesn't need to be heap
heapq.nsmallest(k,q) # q doesn't need to heap
(6) collections.Counter
a=Counter([1,1,2,2,2,3])
a[1]
a[1]+=1
a.update([1,1,2])
del a[1]
(7) list
a=[1,2,3]
a.append()
a.pop()
a.copy()
(8) @lru_cache(None)
(9) sorted(iterable, key, reverse=False) # ascending
- C++
(1) vector
vector<int> a;
a.begin() //iterator
a.end()
a.size()
a.empty()
a[0]
a.at(0)
a.front()
a.back()
a.push_back(1)
a.pop_back()
a.erase(index)
a.clear()
(2) deque
deque<int> a;
a.begin() //iterator
a.end()
a[0]
a.at(0)
a.front()
a.back()
a.push_front(1)
a.push_back(1)
a.pop_fron()
a.pop_back()
(3) dict
unordered_map is hash table, but map is a balanced search tree which is sorted and search is O(log(N))
在这里插入代码片
https://leetcode.com/discuss/study-guide/1154632/c-stl-powerful-guide-compiled-list-of-popular-stl-operations
文章来源:https://blog.csdn.net/UniversityGrass/article/details/134962683
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!