
数据结构
文章平均质量分 52
github_30830155
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
snapshot
环境文件说明流程图代码说明成员变量成员函数检查有效性合法性setget属性值单元测试说明github链接改进之处环境c++ boost库(split和正则) 单元测试google test工具文件说明SnapShot.h : 头文件 SnapShot.cpp : 实现函数 SnapShotTest.cpp : 使用gtest工具单元测试代码run_main.cpp :原创 2016-09-21 02:34:38 · 2702 阅读 · 0 评论 -
删除链表奇数元素
/*功能: 删除队列中的奇数元素思路: 队列是先进先出,前面删除后面插入的了,所以呢 我们就从前面开始,删除,偶数的话就插到队尾,奇数就不管咯 结束条件呢,就是原来的队尾都删除了吧*/// 如果要用链队好了#include#includetypedef struct qnode{ int data; struct qnode *n原创 2016-07-03 22:35:40 · 2532 阅读 · 0 评论 -
Delete Node in a Linked List
Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are原创 2015-12-31 09:16:03 · 235 阅读 · 0 评论 -
Sum of Two Integers
Sum of Two Integers Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3.思路 不用加减实现求和,有点意思 于是百度发现类似的不用原创 2016-07-02 14:04:14 · 283 阅读 · 0 评论 -
Intersection of Two Arrays
Intersection of Two Arrays Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the原创 2016-07-02 12:08:49 · 221 阅读 · 0 评论 -
Reverse String
重新开始刷题吧!!!Reverse String Write a function that takes a string as input and returns the string reversed. Example: Given s = “hello”, return “olleh”.思路 这么简单,循环一遍不就行了,t[i] = s[length-i-1]原创 2016-07-02 11:15:27 · 297 阅读 · 0 评论 -
Counting Bits
Counting Bits Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array. Exampl原创 2016-04-07 10:09:27 · 233 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy on原创 2016-01-07 14:11:38 · 358 阅读 · 0 评论 -
Binary Tree Preorder Traversal
Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes’ values. For example: Given binary tree {1,#,2,3}, 1 \ 2 /原创 2016-04-11 10:19:15 · 245 阅读 · 0 评论 -
Add Two Numbers
Number of 1 Bits iven an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution. For原创 2016-04-11 08:45:57 · 340 阅读 · 0 评论 -
Reverse Linked List
Reverse Linked List Reverse a singly linked list.思路 我居然还纠结了一下下。。。 基本功哇代码非递归/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode原创 2016-04-08 17:19:49 · 200 阅读 · 0 评论 -
删除链队奇数元素
/*功能: 删除队列中的奇数元素思路: 队列是先进先出,前面删除后面插入的了,所以呢 我们就从前面开始,删除,偶数的话就插到队尾,奇数就不管咯 结束条件呢,就是原来的队尾都删除了吧*/// 如果要用链队好了#include#includetypedef struct qnode{ int data; struct qnode *n原创 2016-07-03 23:48:51 · 758 阅读 · 0 评论 -
Print Book
#include #include #include #include using namespace std;class Book{public: Book(string format) { this->book_format = format; setPageStyle(book_format); this->FirstLineChar = '='; th原创 2016-07-29 23:48:18 · 1354 阅读 · 0 评论 -
面试题2
题目好像也忘记了,大概是123 每位数字之和为1+2+3 = 6, 然后1111011,然后加起来也是6,所以给定n,小于n但是符合这样规律的数字有多少个。思路最基本的大概就是循环吧,不过超时了。。。。显然了。。。超时的代码#include<iostream>using namespace std;int sum_x(int x,int g){ int sum = 0; w原创 2016-09-07 16:48:29 · 340 阅读 · 0 评论 -
面试题1
题目有点忘记了,大概就是4/7是lucky num吧,然后仅有4/7组成的数字,依次排列 4,7,44,47,74,77,444….这样的,给定i,表示第几个这样的数,求输入数字思路人啊,千万不能急了,大概思路是对的,细节还是考虑好,结果也不咋的 要淡定了求出有多少位吧, floor(log2(i+1))然后看第一位是4还是7,求中间的那个分界位数long half = (long)pow(原创 2016-09-07 16:08:08 · 345 阅读 · 0 评论 -
动态规划-选学生
题目有 n 个学生站成一排,每个学生有一个能力值, 从这 n 个学生中按照顺序选取 k 名学生, 要求相邻两个学生的位置编号的差不超过 d, 使得这 k 个学生的能力值的乘积最大,你能返回最大的乘积吗 输入描述: 每个输入包含 1 个测试用例。 每个测试数据的第一行包含一个整数 n (1 <= n <= 50), 表示学生的个数, 接下来的一行,包含 n 个整数,原创 2016-09-18 12:57:41 · 412 阅读 · 0 评论 -
Ctrip Online
No.1以前写过 Leetcode 原题 Best time to sell stock但是输入输出要自己写,然后很蠢的是数字用逗号隔开的,要处理代码(逗号分割数字)——1string读入,然后逗号变成空格, 变成stringstream 流,转成字符串,太复杂了int main(){ string strTemp; //int array[4]; //int i原创 2016-09-17 23:56:17 · 556 阅读 · 0 评论 -
minJump
题目小易来到了一条石板路前,每块石板上从1挨着编号为:1、2、3……. 这条石板路要根据特殊的规则才能前进:对于小易当前所在的编号为K的 石板, 小易单次只能往前跳K的一个约数(不含1和K)步,即跳到K+X(X为K的一个非1和本身的约数)的位置。 小易当前处在编号为N的石板,他想跳到编号恰好为M的石板去,小易想知道最少需要跳跃几次可以到达。 例如: N = 4,M = 24: 4->6-原创 2016-09-16 22:44:37 · 472 阅读 · 0 评论 -
BUY apples
题目 小易去附近的商店买苹果,奸诈的商贩使用了捆绑交易, 只提供6个每袋和8个每袋的包装(包装不可拆分)。 可是小易现在只想购买恰好n个苹果,小易想购买尽量少的袋数方便携带。 如果不能购买恰好n个苹果,小易将不会购买。 输入一个整数n,表示小易想购买n(1 ≤ n ≤ 100)个苹果 输出一个整数表示最少需要购买的袋数,如果不能买恰好n个苹果则输出-1思路1可原创 2016-09-16 21:01:51 · 512 阅读 · 0 评论 -
rev
题目/* 对于一个整数X,定义操作rev(X)为将X按数位翻转过来,并且去除掉前导0。 如果 X = 123,则rev(X) = 321; 如果 X = 100,则rev(X) = 1. 现在给出整数x和y,要求rev(rev(x) + rev(y))为多少? input:输入为一行,x、y(1 ≤ x、y ≤ 1000),以空格隔开 output: rev(rev(x) + rev原创 2016-09-16 14:42:22 · 676 阅读 · 0 评论 -
优雅的点
题目 小易有一个圆心在坐标原点的圆,小易知道圆的半径的平方。小易认为在圆上的点而且横纵坐标都是整数的点是优雅的,小易现在想寻找一个算法计算出优雅的点的个数,请你来帮帮他。 例如:半径的平方如果为25 优雅的点就有:(+/-3, +/-4), (+/-4, +/-3), (0, +/-5) (+/-5, 0),一共12个点。 输入: 输入为一个整数,即为圆半径的平方,范围在3原创 2016-09-16 14:39:15 · 413 阅读 · 0 评论 -
BigInt
题目用string模拟int大数运算,记得网易的一个笔试题最后就是的调试错误解决 #include <string>依旧报错string未定义 因为木有using namespace std; 转换到 coff 期间失败 项目属性 — 配置属性 — 清单工具 — 点击输入输出 将右侧出现的嵌入清单的属性值修改为否,点击应用,点击确定 参考程序地址git原创 2016-09-14 16:20:25 · 1198 阅读 · 0 评论 -
Guess Number Higher or Lower
Guess Number Higher or Lower We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I’ll te原创 2016-07-31 22:34:19 · 238 阅读 · 0 评论 -
Spiral Matrix II
Spiral Matrix II Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the following matrix: [原创 2016-03-15 11:20:34 · 213 阅读 · 0 评论 -
Spiral Matrix
Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4,原创 2016-03-15 10:28:37 · 293 阅读 · 0 评论 -
Best Time to Buy and Sell Stock II
Move Zeroes Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you原创 2016-01-14 16:47:45 · 277 阅读 · 0 评论 -
Contains Duplicate
Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false原创 2016-01-13 10:46:15 · 357 阅读 · 0 评论 -
Roman to Integer
Roman to Integer Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.思路 罗马数字好累啊,原则就是有个map,大的在右边就是减,左边就是加 I 是1, V是5 IV 4 VI 6代码clas原创 2016-01-26 10:29:56 · 234 阅读 · 0 评论 -
Majority Element
Majority Element Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the原创 2016-01-25 10:04:58 · 267 阅读 · 0 评论 -
Product of Array Except Self
Product of Array Except Self Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve原创 2016-01-06 15:58:16 · 232 阅读 · 0 评论 -
Single Number III
Single Number III Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.原创 2016-01-05 13:05:38 · 264 阅读 · 0 评论 -
Single Number II
题目Given an array of integers, every element appears three timesexcept for one. Find that single one.其他出现3次,找出唯一出现1次的Note:Your algorithm should have a linear runtime complexity. Could转载 2016-01-05 10:05:55 · 274 阅读 · 0 评论 -
Same Tree
Move Zeroes Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value原创 2016-01-04 09:49:13 · 303 阅读 · 0 评论 -
Invert a binary tree
Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are原创 2015-12-31 10:45:52 · 316 阅读 · 0 评论 -
single number
single number Given an array of integers, every element appears twice except for one. Find that single one. 就是只有一个数不同,其他都是两两相同,找出来这个数 Note: Your algorithm should have a linear ru原创 2015-12-30 10:29:08 · 208 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III
Best Time to Buy and Sell Stock III Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at mo原创 2016-01-15 09:35:26 · 236 阅读 · 0 评论 -
Bulb Switcher
Bulb Switcher There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off原创 2016-01-15 11:00:47 · 264 阅读 · 0 评论 -
Number of 1 Bits
Number of 1 Bits Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11’ has binary rep原创 2016-01-26 10:35:42 · 233 阅读 · 0 评论 -
顺时针旋转矩阵
方法是网上找的一开始我想的好复杂,一圈圈的记录vector,然后改变顺序再赋值结果!!!!记录个pre 和 cur 就好了,还是原地的思路啊思路啊不过还是有陷阱就是,若是没处理以行/列,不改变值得话,那么交叉位置每个顶角会重复访问啊 好久不看c++,好多都忘记了/*Rotate Matrix.Given a matrix, clockwise rotate el原创 2016-03-14 21:38:27 · 527 阅读 · 0 评论 -
Count Primes
目录目录Count Primes思路代码1整除代码2Sieve of Eratosthenes算法描述源码Count Primes题目链接 count primes Count the number of prime numbers less than a non-negative number, n. 即,n之前有多少质数思路 这个题目不难,但是它给的hint很多原创 2016-04-07 09:33:07 · 264 阅读 · 0 评论