C++
文章平均质量分 58
Nereus_Li
这个作者很懒,什么都没留下…
展开
-
快速排序法(三)
/*这个快速排序算法在轴的选取上采用它以最右边的值s作比较的标准,将整个数列分为三个部份,一个是小于s的部份,一个是大于s的部份,一个是未处理的部份*/#include #include using namespace std;#define swap(x,y){int t = x; x = y; y = t;}void fast_shot(int a[],int begi原创 2013-07-31 08:47:17 · 737 阅读 · 0 评论 -
Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.解题思路:题目很简单,可就是没想到有什么高效的方法.我遍历了两遍vector,显得有点复杂.#include#includeusing namespace std;void setZeroes(v原创 2015-02-03 20:45:54 · 802 阅读 · 0 评论 -
Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.解题思路:一开始想到比较简单的方法是用哈希,建立一个索引与结点的m原创 2015-02-02 15:52:08 · 537 阅读 · 0 评论 -
Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2015-02-01 21:13:38 · 625 阅读 · 0 评论 -
Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2015-02-02 13:45:38 · 665 阅读 · 0 评论 -
Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2015-01-31 16:50:46 · 593 阅读 · 0 评论 -
Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2015-01-30 14:21:09 · 650 阅读 · 0 评论 -
Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2015-01-30 19:42:00 · 669 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:采用中序排列的方法递归地决定每个结点的数值;#include#include#includeusing namespace std;//Definition原创 2015-01-30 12:59:30 · 680 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解题思路:一般而言,合并两个有序链表较为简单,只需要两两逐个比较即可.而本题要求合并K个有序链表,事实上只需要对每个链表的头结点建堆.每次输出最小值.并插入其所在链表的下个结点并维护堆.可以利用S原创 2015-01-31 13:48:22 · 551 阅读 · 0 评论 -
Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without原创 2015-01-29 13:30:29 · 569 阅读 · 0 评论 -
Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve原创 2015-01-30 00:24:17 · 774 阅读 · 0 评论 -
SVM
本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com 前言: 又有很长的一段时间没有更新博客了,距离上次更新已经有两个月的时间了。其中一个很大的原因是,不知道写什么好-_-,最近一段时间看了看关于SVM(Support Vector Machine)的文章,觉得SVM是一个非常有趣,而且自成一派的方向,所以今天准备写一篇关于关于SVM的文章。转载 2013-09-23 10:28:48 · 730 阅读 · 0 评论 -
快速排序(1)
快速排序方法有很多,最近总结了一些。今天总结的是姑且记为快速排序(1),其方法的原理很简单,对于一组数列将最左边的数设定为轴,并记录其值为s,然后进行廻圈处理:1.从S值开始以索引i往数组右边搜索,直到找到大于s 的数2.从数组最后一个数开始以索引j向左搜索,直到找到小于s 的数3.如果两个索引i>j,则结束循环4.如果i 5.将左侧的轴与j 进行交换6.对轴左边进行递回对原创 2013-07-28 14:06:48 · 731 阅读 · 0 评论 -
快速排序法(二)
快速排序法的效率在于轴的选取,本方法选取中间值作为轴。具体方法如下:1.同样的先得右找比s大的索引i,然后找比s小的索引j;2.只要两边的索引还没有交会,就交换i 与j 的元素值;3.这次不用再进行轴的交换了,因为在寻找交换的过程中,轴位置的元素也会参与交换的动作;#include #include using namespace std;#define swap(x,y原创 2013-07-29 08:00:15 · 676 阅读 · 0 评论 -
Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2015-02-03 14:16:43 · 493 阅读 · 0 评论