
LeetCode
Comprehensive introduction to the foundational skills of a sophisticated developer
David_Hernandez
NLP
展开
-
Algorithm Foundation 之 排序
Algorithm Foundation 之 排序1. Sort1.1 Insertion Sort1.1.1 Direct Insertion Sort 直接插入排序1.1.2 Shell Sort1.2 Selection Sort1.2.1 Simple Selection Sort1.2.2 Heap Sort 堆排序1.2.2.1 应用 (重点)1.3 交换排序1.3.1 冒泡排序1.3...原创 2019-05-21 14:59:23 · 698 阅读 · 0 评论 -
求最大公约数和最小公倍数
#include <iostream>#include <string>using namespace std;int main(){ int i, j; int temp; cin >> i >> j; if (i < j) { temp = i; i = j; j = temp; }原创 2016-02-25 09:52:03 · 679 阅读 · 0 评论 -
求n的所有素数
#include <iostream>#include <string>#include <vector>using namespace std;int main(){ int n; vector<int> restore; cin >> n; bool flag; for (size_t i = 2; i <= n; i++) {原创 2016-02-25 11:05:28 · 632 阅读 · 0 评论 -
数字反向
将数字逆序 如:输入:7631,反转后为:1367#include <iostream>using namespace std;int main(){ int in; cout << "请输入反转的数字:"; cin >> in; int sum = 0; int temp = in; while (true) { if原创 2016-02-28 15:38:33 · 1304 阅读 · 0 评论 -
输出字符串中的整型值
题目: 编写一个递归函数,其功能是:输入一个字符串,字符间都有空格,输出一个整型值。如:“1 x 2 y z 3 d h 4 g 5 “,输出为54321。#include <iostream>#include<string>using namespace std;void print(string input);int main(){ string in = "1 x 2原创 2016-02-28 11:09:03 · 1393 阅读 · 0 评论 -
统计单词出现的次数
对于map容器,如果下标所表示的键在容器中不存在,则添加新元素。#include <iostream>#include <string>#include <map>using namespace std;int main(){ map<string, int > wordCount; string word; cout << "Enter some words(ctr原创 2016-03-08 09:36:22 · 1024 阅读 · 0 评论 -
利用反正切函数展开计算∏的近似值
当x = 1时,arctan(x)的值即为∏/4的近似值#include <iostream>#include <cmath>using namespace std;int main(){ double x, i, a, sum = 0; cout << "请输入正切值: " << endl; cin >> x; i = 1; a = x; w原创 2016-02-25 13:41:32 · 5326 阅读 · 1 评论 -
求第100002个素数
public class _100002SuShu{ public static void main(String args[]) { double s = System.nanoTime(); int a[] = new int[100002]; int num=7,i,k,flag=4,x=1; a[0]=2转载 2016-02-25 13:14:11 · 1628 阅读 · 0 评论 -
逆向打印字符串--递归实现
#include <iostream> #include <string>using namespace std;void stringReverse( string, int );int main(){ string s = "Print this string backward."; cout << s << '\n'; stringReverse( s, 0 );原创 2016-02-28 20:57:35 · 828 阅读 · 0 评论 -
时间和日期迭代
时间迭代一秒,分钟、小时、天进行变化Time.h#ifndef TIME_H#define TIME_Hclass Time {public: Time( int = 0, int = 0, int = 0 ); // default constructor // set functions void setTime( int, int, int ); // set hour,原创 2016-02-29 15:24:35 · 1584 阅读 · 0 评论 -
选择排序--递归实现
#include <iostream> #include <cstdlib>#include <ctime>using namespace std;void selectionSort( int [], int );int main(){ const int SIZE = 10; const int MAXRANGE = 1000; int sortThisArray[ S原创 2016-02-28 21:09:41 · 5940 阅读 · 2 评论 -
读书模拟
#include <iostream>#include <string>#include <set>#include <vector>#include <ctime>#include <cstdlib>using namespace std;int main(){ /* * 定义一个vector容器,存储你在未来六个月里要阅读的书,再定义一个set,用于记录你已经看原创 2016-03-08 14:24:12 · 395 阅读 · 0 评论 -
幂指函数的递归实现
#include <iostream>using namespace std;long power(long base, long exponent);int main(){ int base, exponent; cout << "请输入底数: "; cin >> base; cout << "请输入幂: "; cin >> exponent;原创 2016-02-28 15:53:32 · 844 阅读 · 0 评论 -
求n的阶乘和
形如:1!+2!+3!+ … +n!形式#include <iostream>#include <string>using namespace std;int main(){ int n; cin >> n; int multiAmass = 1; int sum = 0; for (size_t i = 1; i <= n; i++) {原创 2016-02-25 10:01:52 · 1369 阅读 · 0 评论 -
计算共有多少个单词,并输出最长和最短的单词
#include <iostream>#include <cctype>#include <string>#include <vector>using namespace std;int main(){ /* * 已知有如下string对象: * string line1 = "We were her pride of 10 she named us:";原创 2016-03-07 14:56:34 · 1261 阅读 · 0 评论 -
交换两个数的五种方法
方法一:使用第三个变量交换int a = 10;int b = 20;int tem = a;a = b;b = temp;cout 方法二:使用算术运算int a = 10;int b = 20;a = b - a;b = b - a;a = b + a;cout 方法三:使用指针地址int *a,*b; //假设*a = new int(1原创 2015-08-24 11:09:26 · 769 阅读 · 0 评论 -
找出数组中的最小值--递归实现
#include <iostream> #include <iomanip> #include <cstdlib>#include <ctime>using namespace std;const int MAXRANGE = 1000;int recursiveMinimum( const int [], int, int );int main(){ const int SIZE原创 2016-02-28 21:16:35 · 4543 阅读 · 0 评论 -
桶排序
#include <iostream>#include <iomanip>using namespace std;const int SIZE = 10;void zeroBucket(int buckets[][SIZE]);void bucketSort(int a[]);int numberOfDigits(int b[], int arraySize);void distribut原创 2016-03-17 11:05:17 · 395 阅读 · 0 评论 -
回文--递归实现
回文形如:“radar“#include <iostream> #include <string>using namespace std;bool testPalindrome( string, int, int );int main(){ string input; cout << "Enter a sentence:\n"; getline( cin, input );原创 2016-02-28 20:30:17 · 1003 阅读 · 0 评论 -
LR 和 SVM 的区别与联系
LR 和 SVM 的区别与联系联系都是分类算法 在很大一部分人眼里,LR是回归算法。我是非常不赞同这一点的,因为我认为判断一个算法是分类还是回归算法的唯一标准就是样本label的类型,如果label是离散的,就是分类算法,如果label是连续的,就是回归算法。很明显,LR的训练数据的label是“0或者1”,当然是分类算法。其实这样不重要啦,暂且迁就我认为他是分类算法吧,再说...原创 2018-04-27 12:05:35 · 4209 阅读 · 0 评论 -
快速排序--递归实现
#include <iostream> #include <iomanip> #include <cstdlib>#include <ctime>using namespace std;const int SIZE = 10;const int MAX_NUMBER = 1000;void quicksort( int * const, int, int );int partition(原创 2016-02-29 11:17:25 · 420 阅读 · 0 评论 -
四舍五入到特定的小数位置
使用floor函数把数字舍入到特定的小数位置 0.05舍入到十分位为0.1; 0.005舍入到百分位为0.01;#include <iostream>#include <cmath>using namespace std;int main(){ double n; int point; cout << "输入数字:"; cin >> n; cout原创 2016-02-28 16:20:21 · 551 阅读 · 0 评论 -
LeetCode 常用算法
LeetCode 常用算法1. 二分查找2. 广度优先搜索3. 深度优先搜索4. 排列5. 组合5. 链表5.1 反转链表5.2 链表两两交换元素5.3 链表检测成环5.4 查找链表的倒数第 K 个元素5.5 查找链表的中间元素5.6 查找链表成环位置的元素6. 排序6.1 Shell 希尔排序6.2 选择排序6.3 快速排序1. 二分查找def binary_search(data, target, left, right): while left <= right: m原创 2021-02-27 20:51:27 · 1819 阅读 · 0 评论 -
LeetCode 刷题之 Add Two Numbers
LeetCode 刷题之 Add Two Numbers/** * @Time : 20/03/2018 09:54 * @Author : lotus * @File : AddTwoNumbers.java * @Software: IntelliJ IDEA * @Desc : * @license : Copyright(C), Alex * @Contact : ale...原创 2018-03-20 11:34:06 · 266 阅读 · 0 评论 -
LeetCode 刷题之 Reverse Integer
LeetCode 刷题之 Reverse Integer/** * @Time : 19/03/2018 10:18 * @Author : lotus * @File : ReverseInteger.java * @Software: IntelliJ IDEA * @Desc : * @license : Copyright(C), Alex * @Contact : al...原创 2018-03-19 12:03:28 · 357 阅读 · 0 评论 -
LeetCode 刷题之 ZigZag Conversion
LeetCode 刷题之 ZigZag Conversion/** * @Time : 18/03/2018 15:59 * @Author : lotus * @File : ZigzagPattern.java * @Software: IntelliJ IDEA * @Desc : * @license : Copyright(C), Alex * @Contact :...原创 2018-03-18 20:44:01 · 304 阅读 · 0 评论