
做题
有态度的我
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
hackerank-stringstream
stringstream将字符串对象与流相关联,使您可以像对待流一样读取字符串(如cin)。 // CPP program to count words in a string // using stringstream. #include <bits/stdc++.h> using namespace std; int countWords(string str) {...原创 2020-02-02 12:53:14 · 384 阅读 · 0 评论 -
hackerank - 30daysof code (29 )-bit wise and
C或C ++中的&(按位与)将两个数字作为操作数,并对两个数字的每一位进行“与”运算。仅当两个位均为1时,AND的结果才为1。 该 | C或C ++中的(按位或)将两个数字作为操作数,并对两个数字的每一位进行“或”运算。如果两个位中的任何一个为1,则OR的结果为1。 C或C ++中的^(按位XOR)将两个数字用作操作数,并对两个数字的每一位进行XOR。如果两个位不同,则XOR的结果为1。 在C...原创 2020-02-02 11:18:10 · 310 阅读 · 0 评论 -
hackerank -30days ofcode ---(28)string & multiset
insert() 多集是按照特定顺序存储元素的容器,其中多个元素可以具有相等的值。在内部,多重集中的元素总是按照其内部比较对象(类型为Compare)指示的特定严格弱排序标准进行排序。 以下代码来自geek forgeek // unordered_multiset::insert #include <array> #include <iostream> #inc...原创 2020-02-02 01:14:00 · 244 阅读 · 1 评论 -
hackerank -30 daysofcode-prime
如何检验一个数是否是质数 #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here...原创 2020-02-01 23:32:35 · 168 阅读 · 0 评论 -
hackerank -20 days ofcode-linked list
Node* removeDuplicates(Node *head) { //Write your code here if(head == nullptr) return 0; Node* it = head; while (it!=nu...原创 2020-02-01 22:48:11 · 128 阅读 · 0 评论 -
hackerrank-30 days of code --BST TRAVERSAL
void levelOrder(Node * root){ //Write your code here std::queue<Node*> q; Node* c; if(root != NULL) { q.push(root); } while (!q.empty()) ...原创 2020-02-01 22:26:37 · 131 阅读 · 0 评论 -
hackerank-30 days ofcoding-template
generic programming优点是 1.代码可重用性 2.避免函数重载 3.编写后,可以多次使用。 用法: template <typename T> typename and class are interchangeable in the basic case of specifying a template: template<class T> clas...原创 2020-02-01 21:32:17 · 204 阅读 · 0 评论 -
hackerank-30days of code-BST
应该大家都挺熟悉的, BST 的特点: 节点的左子树仅包含其键小于该节点的键的节点。 节点的右子树仅包含键大于该节点的键的节点。 左和右子树也都必须是二进制搜索树。 这道题是计算BST 的高度, 首先从root开始,然后分别计算左右孩子的高度, 然后 因为是算edge,所以就不用+1; int getHeight(Node* root){ //Write your co...原创 2020-02-01 14:41:25 · 235 阅读 · 0 评论 -
hackerank-30 days of code-day 20 -sorting
1.这道题有关于数组的排序问题,关于sorting,主要有以下几种algorithm: selection sort 选择排序算法通过从未排序部分重复查找最小元素(考虑升序)并将其放在开头来对数组进行排序。该算法在给定数组中维护两个子数组。 1)已排序的子数组。 2)未排序的剩余子数组。 在选择排序的每次迭代中,都会从未排序的子数组中选取最小元素(考虑升序)并将其移至已排序的子数组。 arr ...原创 2020-01-31 14:16:24 · 296 阅读 · 0 评论 -
hackerank-30 days of code -m stack and queuec
栈与队列 LIFO 堆栈是一种容器适配器,stack作为容器适配器的实现,c++语言可以通过在头文件中包括 使用std::stack 构造一个堆容器对象,这个对象一共有7个可使用函数: emplace: 此函数用于将新元素插入堆栈容器,新元素添加到堆栈顶部。与push不一样的是在使用emplace的时候,新插入的元素需要作为参数传递。 empty: return whether the stac...原创 2020-01-28 15:53:31 · 192 阅读 · 0 评论 -
Hackerank- 30 days of code-17-class
建一个叫Calculator的class里面有一个power函数, 本来这个不难,但是有个要求是如果当n或者p为负数的时候,需要返回一段字符串,但是写死的main函数里面对于这个class的函数使用是直接返回int, 所以如何在函数需要返回int的时候只返回错误字符串,而不返回int呢 ##代码 class Calculator { public: int power(in...原创 2020-01-27 23:04:29 · 278 阅读 · 0 评论 -
Hackerank- 30 days of code-linked list
insert function: 创建newNode(use constructor); 如果head = NULL,返回这个newNode 如果有head, 那么找到这个list的最后一个,用的方法是,while loop, 先用it = head,然后while(it->next!=NULL)当whileloop停止的时候, it指到list最后一个, it->next = new...原创 2020-01-27 18:24:05 · 209 阅读 · 0 评论