自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(123)
  • 收藏
  • 关注

原创 leetcode 373. Find K Pairs with Smallest Sums

373. Find K Pairs with Smallest Sums代码如下:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *columnSizes array. * Note: Both returned array and *columnSi...

2018-03-26 11:09:48 227

原创 leetcode 452. Minimum Number of Arrows to Burst Balloons

代码如下:int findMinArrowShots(int** points, int pointsRowSize, int pointsColSize) { if(pointsRowSize==0) return 0; int cmp(const void* a,const void* b) { int* c; int* ...

2018-03-20 10:26:40 227

原创 leetcode 54. 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, 5, 6 ], [ 7, 8, 9 ]]You shoul...

2018-03-19 10:51:33 191

原创 leetcode 92. Reverse Linked List II

代码如下:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* reverseBetween(struct ListNode* head, int m, int n) { i...

2018-03-19 09:59:17 161

原创 leetcode 134. Gas Station

原题:There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its...

2018-03-13 14:41:04 118

原创 leetcode 673

https://www.cnblogs.com/Atanisi/p/7596135.html参考这个文章的解释,写出了如下代码。经典的动态规划问题,在动态规划的过程中还完成了统计是比较厉害的。这个我有时候处理不好,包括昨天的递归后数据还原的经典思想。C部分的代码如下:int findNumberOfLIS(int* nums, int numsSize) { int d[numsSize+...

2018-03-13 10:50:51 367

原创 leetcode 79. Word Search

原题:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically ...

2018-03-12 17:51:53 148

原创 144. Binary Tree Preorder Traversal

前序遍历/** * Definition for a binary tree node. * struct TreeNode { *     int val; *     struct TreeNode *left; *     struct TreeNode *right; * }; *//** * Return an array of size *returnSize. * Note: The...

2018-03-12 14:42:14 165

原创 leetcode 451. Sort Characters By Frequency

原题:Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Explanation:'e' appears twice while 'r' and 't' both appear once.So 'e' m...

2018-03-06 10:36:28 113

原创 leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee

原题:Your 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 complete as many...

2018-03-02 15:31:00 142

原创 leetcode 122. Best Time to Buy and Sell Stock II

代码如下:。。这个跟基本的动态规划有啥关系,主要还是判断加和关系比较大。。int maxProfit(int* prices, int pricesSize) {    int max = 0;    for (int i = 1; i     if (prices[i] > prices[i - 1]) {      max += (prices[i] - prices[

2018-02-07 11:01:12 117

原创 leetcode 120. Triangle

代码如下:int minimumTotal(int** triangle, int triangleRowSize, int *triangleColSizes) {    int* min;    min=(int*)malloc(sizeof(int)*(triangleColSizes[triangleRowSize-1]));    memset(min,0,sizeof(

2018-02-07 10:49:56 142

原创 leetcode 64. Minimum Path Sum

代码如下:int minPathSum(int** grid, int gridRowSize, int gridColSize) {    int flags[gridRowSize][gridColSize];    flags[0][0]=grid[0][0];    for(int n=0;n    {        for(int m=0;m        {

2018-02-06 15:58:56 151

原创 leetcode 55 动态规划练习

代码如下:bool canJump(int* nums, int numsSize) {    int reach = 0;    for(int n=0;n=n;n++)    {        reach = *(nums+n)+n>reach?*(nums+n)+n:reach;    }    return reach>=numsSize-1;}自己

2018-02-06 14:31:46 249

原创 leetcode 746 动态规划问题 记得复习一下基础知识

代码如下:int minCostClimbingStairs(int* cost, int costSize) {    int* dp;    dp=(int*)malloc(sizeof(int)*costSize);    *dp=0;    *(dp+1)=0;    for(int n=2;n    {        *(dp+n)=(*(dp+n-1)+

2018-02-06 09:49:11 191

原创 leetcode 328

代码如下:/** * Definition for singly-linked list. * struct ListNode { *     int val; *     struct ListNode *next; * }; */struct ListNode* oddEvenList(struct ListNode* head) {    if(head=

2018-02-05 15:14:09 183

原创 leetcode 594

代码如下:int findLHS(int* nums, int numsSize) {    if(numsSize        return 0;    int cmp(const void* a,const void* b)    {        return *(int*)a-*(int*)b;    }    int result = 0;    q

2018-02-05 11:17:58 187

原创 leetcode 565. Array Nesting

原题:A 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 below

2017-12-11 11:21:55 150

原创 leetcode 665. Non-decreasing Array

原题:Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing if array[i]  holds for every 

2017-12-05 10:08:32 175

原创 leetcode 94. Binary Tree Inorder Traversal

原题:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note: Recur

2017-12-04 10:01:51 139

原创 leetcode 382. Linked List Random Node

原题:Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.Follow up:What if the linked list is extremely la

2017-12-01 10:37:55 182

原创 leetcode 686. Repeated String Match

原题:Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1.For example, with A = "abcd" and B = "cda

2017-11-30 15:24:11 226

原创 leetcode 458. Poor Pigs

原题:There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. They all look the same. If a pig drinks that poison it will die within 15 minutes. What is th

2017-11-29 14:58:11 232

原创 leetcode 563. Binary Tree Tilt

原题:Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all rig

2017-11-08 11:30:45 183

原创 leetcode 696. Count Binary Substrings

原题:Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutivel

2017-11-08 10:32:50 200

原创 leetcode 676. Implement Magic Dictionary

原题:Implement a magic directory with buildDict, and search methods.For the method buildDict, you'll be given a list of non-repetitive words to build a dictionary.For the method search, yo

2017-10-23 11:38:34 422

原创 leetcode ~~~~~~~~(我也不知道这个题号了。。)

原题:Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,0

2017-10-13 11:01:17 214

原创 leetcode 672. Bulb Switcher II

原题:There 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

2017-10-12 10:03:39 310

原创 leetcode 319. 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 or tur

2017-10-12 09:49:53 118

原创 leetcode 148 sortlist

原题:Sort a linked list in O(n log n) time using constant space complexity.Seen this question in a real interview before?   Yes 然而我把快排写完了才发现超时了。。。真是悲剧。。。/**

2017-10-11 13:52:57 151

原创 leetcode 477. Total Hamming Distance

原题:The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Now your job is to find the total Hamming distance between all pairs o

2017-10-11 10:37:16 226

原创 leetcode 677. Map Sum Pairs

原题:Implement a MapSum class with insert, and sum methods.For the method insert, you'll be given a pair of (string, integer). The string represents the key and the integer represents the va

2017-10-10 15:38:23 266

原创 leetcode 462. Minimum Moves to Equal Array Elements II

原题:Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected

2017-10-10 15:02:48 177

原创 leetcode 695. Max Area of Island(未解决)

原题:Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the gr

2017-10-09 11:47:35 512 4

原创 leetcode 693. Binary Number with Alternating Bits

原题:Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.Example 1:Input: 5Output: TrueExplanation:The binary r

2017-10-09 09:19:06 842

原创 leetcode 303. Range Sum Query - Immutable

原题:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) ->

2017-09-26 10:35:28 193

原创 leetcode 155. Min Stack

原题:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top(

2017-09-26 10:13:26 158

原创 leetcode 448. Find All Numbers Disappeared in an Array

原题:Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this a

2017-09-14 10:09:14 145

原创 leetcode 205. Isomorphic Strings

原题:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced

2017-09-14 09:50:20 159

原创 leetcode 160. 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 ↘

2017-09-13 10:39:49 148

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除