
C/C++
文章平均质量分 58
自犬邦
热爱生活,珍惜时间。
展开
-
如何从字符串中除去逗号
一次偶然的机会,同学接触到一个函数,可以将一串字符串中的逗号以及"-"除去,当然,并不是简单地除去这两个符号。例如 1,2,3,4 处理后变为 1 2 3 41-3,4 处理后变为 1 2 3 4诸如此类的功能。好吧,后面的时间开始编程实现。原创 2015-02-09 12:18:24 · 12275 阅读 · 0 评论 -
leetcode 092 —— Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy t原创 2015-08-05 22:02:04 · 254 阅读 · 0 评论 -
leetcode 027 —— Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.原创 2015-07-13 20:23:52 · 268 阅读 · 0 评论 -
leetcode 028 —— Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.思路:KMP算法原创 2015-07-13 20:27:28 · 249 阅读 · 0 评论 -
leetcode 023 —— Merge k sorted linked lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路,采用小顶堆/** * Definition for singly-linked list. * struct ListNode { * int val; *原创 2015-07-13 14:24:55 · 321 阅读 · 0 评论 -
leetcode 025 —— 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-07-13 15:00:35 · 236 阅读 · 0 评论 -
leetcode 024 —— Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2015-07-13 14:28:59 · 348 阅读 · 0 评论 -
leetcode 015 —— 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c原创 2015-07-08 20:13:49 · 244 阅读 · 0 评论 -
leetcode 003 —— Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2015-04-14 10:35:11 · 319 阅读 · 0 评论 -
leetcode 004 —— Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).方法一:先合并数组,在排序,在搜索中间值。(繁琐)方法二:可以原创 2015-04-14 14:17:50 · 328 阅读 · 0 评论 -
leetcode 007 —— Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321class Solution {public: int reverse(int x) { bool sign = x > 0 ? false : true; /原创 2015-04-27 14:50:27 · 334 阅读 · 0 评论 -
leetcode 006 —— ZigZag Conversion
xxxThe string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA原创 2015-04-17 13:42:37 · 314 阅读 · 0 评论 -
leetcode 005 —— Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.从每个位置,向两边开始扫描。原创 2015-04-16 14:28:00 · 329 阅读 · 0 评论 -
leetcode 002 —— 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-04-13 21:08:32 · 291 阅读 · 0 评论 -
C++零碎知识整理
unordered_map 被推荐取代hash map,其被包含在头文件中,leetcode 第一题可用。原创 2015-04-13 13:35:51 · 281 阅读 · 0 评论 -
Cmath函数
cmath是c++语言中的库函数,类似于C语言的math.h头文件常用的math函数 有 求幂,求对数,求余,等等。using ::abs; //绝对值using ::acos; //反余弦using ::acosf; //反余弦using ::acosl; //反余弦using ::asin; //反正弦using ::a原创 2015-03-24 14:17:24 · 1958 阅读 · 0 评论 -
leetcode 001 —— twosum
1. Two sum Given an array of integers, find two numbers such that they addup to a specific target number.The function twoSum should return indices of the two numberssuch that they add up to t原创 2015-04-13 20:42:38 · 315 阅读 · 0 评论