ARTS 打卡 -07

用户头像
Geek_yansheng25
关注
发布于: 2020 年 07 月 19 日
ARTS打卡-07

Algorithm

Question

Plus One

Given a non-empty array of digits representing a non-negative integer, increment one to the integer.

The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit.

You may assume the integer does not contain any leading zero, except the number 0 itself.

My answer

class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
vector<int> res;
if (digits.empty()) {
res.push_back(1);
}
else if (digits.back() < 9) {
res = digits;
res.back() += 1;
}
else {
vector<int> left = digits;
auto leftNum = digits.size() - 1;
left.resize(leftNum);
res = plusOne(left);
res.push_back(0);
}
return res;
}
};

Review

Apache Cassandra

https://cassandra.apache.org/

https://www.datastax.com/cassandra

Apache Cassandra is an open source, distributed NoSQL database that began internally at Facebook and was released as an open-source project in July 2008. Cassandra delivers continuous availability (zero downtime), high performance, and linear scalability that modern applications require, while also offering operational simplicity and effortless replication across data centers and geographies. Cassandra can handle petabytes of information and thousands of concurrent operations per second, enabling organizations to manage large amounts of data across hybrid cloud and multi cloud environments.

At DataStax, we’re working hard with the open-source community to build on Cassandra’s decade-plus of maturity to solidify its position as the leading database for cloud-native applications.

Tips

1. tmux

  • Install

sudo apt-get install tmux

  • Create a session

tmux new -s <session_name>

  • List out all the running sessions

tmux ls

  • Attach to a running session

tmux attach -t <session_name>

tmux a -t <session_name>

2. git patch

https://www.tutorialspoint.com/git/git_patch_operation.htm

Patch is a text file, whose contents are similar to Git diff, but along with code, it also has metadata about commits; e.g., commit ID, date, commit message, etc. We can create a patch from commits and other people can apply them to their repository.

  • Create patches for the latest N commits

git format-patch -N

  • Create a patch for a specific commit

git format-patch <commit_ID>

The above commands create .patch files inside the current working directory.

  • Modify the local files without creating commit

git apply <patch_name>.patch

  • Modify the file and create commit as well

git am <patch_name>.patch

Share

1. std::move()

https://stackoverflow.com/questions/3413470/what-is-stdmove-and-when-should-it-be-used



  • "What is it?"

While std::move() is technically a function - I would say it isn't really a function. It's sort of a converter between ways the compiler considers an expression's value.

  • "What does it do?"

The first thing to note is that std::move() doesn't actually move anything. It converts an expression from being an lvalue (such as a named variable) to being an xvalue. An xvalue tells the compiler:

You can plunder me, move anything I'm holding and use it elsewhere (since I'm going to be destroyed soon anyway)".

in other words, when you use std::move(x), you're allowing the compiler to cannibalize x. Thus if x has, say, its own buffer in memory - after std::move()ing the compiler can have another object own it instead.

  •  "When should it be used?"

A typical use is 'moving' resources from one object to another instead of copying.

2. std::bind() & placeholders

https://www.geeksforgeeks.org/bind-function-placeholders-c/

  • How does bind() work?

Bind function with the help of placeholders, helps to manipulate the position and number of values to be used by the function and modifies the function according to the desired output.

  • What are placeholders?

Placeholders are namespace which direct the position of a value in a function. They are represented by _1, _2, _3

用户头像

Geek_yansheng25

关注

还未添加个人签名 2020.05.21 加入

还未添加个人简介

评论

发布
暂无评论
ARTS打卡-07