
C++
文章平均质量分 62
农民小飞侠
如果放弃了,那还谈什么理想
展开
-
c++遍历某个路径下的所有文件
正确的代码如下,注意,路径需要用char*格式,否则会出现读不出来的错误。int main(){ struct info *str1; struct info s; long Handle; struct _finddata_t FileInfo; char* dir = "samplepicture\\*.*"; int count = 1; if ((Handl原创 2017-10-17 17:01:19 · 758 阅读 · 0 评论 -
2018搜狐春招在线笔试编程题总结(技术类)
第一道题目是系统设计的题目,我记不清了,好像有规则一,规则二;第二道题目是求一个数据的排序的前K个值,这个太简单了,想都没想,就直接sort弄完了,我这里把我的代码贴出来,欢迎大家来纠错。我用的是C++#include<iostream>#include<map>#include<vector>using namespace std;int main(...原创 2018-04-14 17:49:04 · 673 阅读 · 0 评论 -
[leetcode] 858. Mirror Reflection
感想我搜了一下,好像还没有搜到中文博客关于这一题的解题报告,我这里弥补一下空缺。problemThere is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining cor...原创 2018-07-06 10:03:26 · 623 阅读 · 2 评论 -
[leetcode] 72. Edit Distance动态规划
感想这是我在牛客网上看到的很经典的一个动态规划的题目,我当时也是不怎么懂,这里我把它记录下来,尽量写详细。problemGiven two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 ...原创 2018-05-01 00:16:05 · 296 阅读 · 1 评论 -
[leetcode]16. 3Sum Closest
DescriptionGiven an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each ...最接近的三数之和的C++和Python实现。原创 2019-01-17 20:38:02 · 267 阅读 · 1 评论 -
[leetcode]15. 3Sum
DescriptionGiven an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.三数之和的C++和Python的解法。原创 2019-01-17 20:59:54 · 155 阅读 · 1 评论 -
[leetcode] 454. 4Sum II
DescriptionGiven four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have...原创 2019-01-17 21:11:36 · 217 阅读 · 0 评论 -
[leetcode] 18. 4Sum
DescriptionGiven an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in 四数之和的python和C++代码原创 2019-01-17 21:31:44 · 173 阅读 · 1 评论 -
[leetcode] 456. 132 Pattern
DescriptionGiven a sequence of n integers a1, a2, …, an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and a_i < a_k < a_j. Design an algorithm that takes a list of n numb...原创 2019-01-17 21:51:26 · 156 阅读 · 0 评论 -
[leetcode] 721. Accounts Merge
DescriptionGiven a list accounts, each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the a...原创 2019-01-19 21:07:05 · 451 阅读 · 0 评论 -
[leetcode] 211. Add and Search Word - Data structure design
DescriptionDesign a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing o...原创 2019-01-19 21:19:46 · 254 阅读 · 0 评论 -
[leetcode] 67. Add Binary
DescriptionGiven two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Example 1:Input: a = "11", b = "1"Output: "10...原创 2019-01-19 21:31:43 · 140 阅读 · 1 评论 -
[leetcode] 258. Add Digits
DescriptionGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.Example:Input: 38Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. ...原创 2019-01-19 21:37:36 · 190 阅读 · 0 评论 -
[leetcode] 623. Add One Row to Tree
DescriptionGiven the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1.The adding rule is: given a positi...原创 2019-01-19 21:51:30 · 218 阅读 · 0 评论 -
[leetcode] 445. Add Two Numbers II
DescriptionYou are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers ...原创 2019-01-19 21:56:18 · 192 阅读 · 1 评论 -
[leetcode] 2. Add Two Numbers
DescriptionYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers ...原创 2019-01-19 21:59:51 · 473 阅读 · 1 评论 -
[leetcode] 306. Additive Number
DescriptionAdditive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent numb...原创 2019-01-19 23:50:04 · 169 阅读 · 0 评论 -
[leetcode] 863. All Nodes Distance K in Binary Tree
DescriptionWe are given a binary tree (with root node root), a target node, and an integer value K.Return a list of the values of all nodes that have a distance K from the target node. The answer c...原创 2019-01-20 12:01:34 · 231 阅读 · 0 评论 -
[leetcode] 816. Ambiguous Coordinates
DescriptionWe had some 2-dimensional coordinates, like “(1, 3)” or “(2, 0.5)”. Then, we removed all commas, decimal points, and spaces, and ended up with the string S. Return a list of strings repr...原创 2019-01-20 14:14:09 · 227 阅读 · 0 评论 -
[leetcode] 413. Arithmetic Slices
DescriptionA sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmeti...原创 2019-01-20 14:25:30 · 230 阅读 · 0 评论 -
[leetcode] 441. Arranging Coins
DescriptionYou have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be fo...原创 2019-01-20 14:31:58 · 179 阅读 · 0 评论 -
[leetcode] 565. Array Nesting
DescriptionA zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], … } subjected to the rule belo...原创 2019-01-20 14:50:24 · 598 阅读 · 0 评论 -
[leetcode] 735. Asteroid Collision
DescriptionWe are given an array asteroids of integers representing asteroids in a row.For each asteroid, the absolute value represents its size, and the sign represents its direction (positive mean...原创 2019-01-20 15:02:07 · 304 阅读 · 0 评论 -
[leetcode] 844. Backspace String Compare
DescriptionGiven two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.Example 1:Input: S = "ab#c", T = "ad#c"Output: trueExplan...原创 2019-01-20 15:13:07 · 206 阅读 · 1 评论 -
[leetcode] 682. Baseball Game
DescriptionYou’re now a baseball game point recorder.Given a list of strings, each string can be one of the 4 following types:Integer (one round’s score): Directly represents the number of points ...原创 2019-01-20 15:40:27 · 173 阅读 · 0 评论 -
[leetcode] 227. Basic Calculator II
DescriptionImplement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division...原创 2019-01-20 15:48:23 · 158 阅读 · 0 评论 -
[leetcode] 224. Basic Calculator
DescriptionImplement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers a...原创 2019-01-20 15:58:49 · 264 阅读 · 0 评论 -
[leetcode] 667. Beautiful Arrangement II
DescriptionGiven two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement:Suppose this list is [a1, a2,...原创 2019-01-20 20:13:09 · 206 阅读 · 1 评论 -
[leetcode] 122. Best Time to Buy and Sell Stock II
DescriptionSay 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 like (i...原创 2019-01-20 20:33:10 · 186 阅读 · 1 评论 -
[leetcode] 859. Buddy Strings
DescriptionGiven two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B.Example 1:Input: A = "ab", B = "ba"Output: trueExam...原创 2019-01-31 14:16:20 · 195 阅读 · 0 评论 -
[leetcode] 672. Bulb Switcher II
DescriptionThere is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different ...原创 2019-01-31 14:48:37 · 178 阅读 · 0 评论 -
[leetcode] 319. Bulb Switcher
DescriptionThere 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 or ...原创 2019-01-31 14:54:27 · 237 阅读 · 0 评论 -
[leetcode] 123. Best Time to Buy and Sell Stock III
DescriptionSay 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 most two transactions.Note: You...原创 2019-01-22 00:21:56 · 174 阅读 · 1 评论 -
[leetcode] 299. Bulls and Cows
DescriptionYou are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provid...原创 2019-01-31 21:24:15 · 283 阅读 · 0 评论 -
[leetcode] 464. Can I Win
DescriptionIn the “100 game,” two players take turns adding, to a running total, any integer from 1…10. The player who first causes the running total to reach or exceed 100 wins.What if we change th...原创 2019-01-31 22:02:53 · 168 阅读 · 0 评论 -
[leetcode] 542. 01 Matrix
说明本篇博客的宗旨是力求用非常通俗的讲解leetcode上的题目,降低学习者理解学习的门槛。DescriptionGiven a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Exampl...原创 2019-01-16 20:36:54 · 275 阅读 · 1 评论 -
[leetcode] 650. 2 Keys Keyboard
DescriptionInitially on a notepad only one character ‘A’ is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (p...原创 2019-01-16 21:02:48 · 184 阅读 · 0 评论 -
[leetcode] 717. 1-bit and 2-bit Characters
DescriptionWe have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).Now given a string represented by sever...原创 2019-01-16 21:23:04 · 179 阅读 · 0 评论 -
[leetcode] 714. Best Time to Buy and Sell Stock with Transaction Fee
DescriptionYour are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee.You may comple...原创 2019-01-27 23:43:18 · 251 阅读 · 0 评论 -
[leetcode] 121. Best Time to Buy and Sell Stock
DescriptionSay 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 (i.e., buy one and sell one share of ...原创 2019-01-27 23:50:06 · 205 阅读 · 1 评论