自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

浮生琴弦

ONE is all.

  • 博客(23)
  • 收藏
  • 关注

原创 LeetCode #329: Longest Increasing Path in a Matrix

Problem Statement(Source) Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diago

2016-08-31 20:45:13 397

原创 LeetCode #99: Recover Binary Search Tree

Problem Statement(Source) Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure.Note: A solution using O(n) space is pretty straight forwar

2016-08-31 09:33:55 266

原创 LeetCode #312: Burst Balloons

Problem Statement(Source) Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst ballo

2016-08-30 12:17:24 373

原创 LeetCode #382: Linked List Random Node

Problem Statement(Problem Link) 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 li

2016-08-29 09:06:40 470

原创 LeetCode #3: Longest Substring Without Repeating Characters

Problem Statement(Problem Link) Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb"

2016-08-27 11:09:26 418

原创 LeetCode #2: Add Two Numbers

Problem StatementYou 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 ret

2016-08-27 10:02:47 394

原创 LeetCode #1: Two Sum

Problem Statement(Problem Link) Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.E

2016-08-27 09:42:51 365

原创 PIQ60: Leaders in an array

Problem StatementGiven an array of integers, find the leaders in the array. A leader is an element which is larger than all the elements in the array to its right.SolutionUse a stack.def leaders(nums):

2016-08-23 14:33:50 286

原创 PIQ59: Find the missing number in the increasing sequence

Problem StatementGiven an increasing sequence of numbers from 1 to n with only one missing number, how can you find that missing number without traversing the sequence in linear fashion. In other words

2016-08-23 12:51:52 380

原创 PIQ07: Longest Palindromic Subsequence

Problem StatementGiven a string S, Find the length of the longest palindromic subsequence.Approach 1Reverse S to T, then make use of the Longest Common Subsequence algorithm.Approach 2Dynamic programmi

2016-08-23 11:45:01 306

原创 PIQ26: Longest Palindromic Substring

Problem StatementGiven a string S, find the longest palindromic substring of S.def longest_palindromic_substring(s): if not s: return None n = len(s) lps, lps_len = s[0], 1 dp =

2016-08-23 09:46:27 216

原创 PIQ39: Longest Common Subsequence

Problem StatementGiven two string s1 and s2. Find the longest common subsequence between s1 and s2.Link@HackerRank: The Longest Common Subsequencedef longest_common_subsequence(s1, s2): """Find the

2016-08-23 09:00:05 307

原创 LeetCode #132: Palindrome Partitioning II

Problem statementGiven a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = “aab”

2016-08-22 20:55:22 550

原创 PIQ19: Longest Common Substring

Problem Statement:Given two strings S1 and S2, find the longest common substring between S1 and S2.Approach 1: Dynamic Programmingdef LCS(s1, s2): """ Time complexity: O(n^2) Space complexi

2016-08-22 14:15:41 267

原创 PIQ18: Delete middle node of a linked list

Problem statement Given a pointer to the middle node of the linked list, delete that node.Solution# Definition for singly-linked list.class ListNode(object): def __init__(self, x): self.v

2016-08-22 13:51:25 283

原创 PIQ12: Find pivot in a sorted rotated array

Description: Given a sorted integer array which may have been rotated once, find the pivot index, i.e. index of the minimum element of the array.Approach 1: Naive Solutiondef pivot(nums): """ T

2016-08-22 13:39:37 318

原创 PIQ03: Find Majority Element in an Array

Description: Given an array of size n, find the element which occurs more than n/2 times. This element is called Majority Element. If not found, return null.Approach 1: use a counterdef majority_elemen

2016-08-22 07:33:40 324

原创 LeetCode: 371. Sum of Two Integers

Original ProblemCalculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.Solutiondef

2016-08-22 07:15:42 230

原创 Remove duplicates from array (Python)

1. 给定一个list, 写一个函数去掉其中的重复元素(不需要保持原始相对顺序)。

2016-08-21 07:58:47 552

原创 HackerRank: Play with words

题目链接分析经典动态规划问题“最长回文子串(Longest Palindromic Subsequence)”的变形。动态规划#!/usr/bin/pythons = raw_input()n = len(s)dp = [[0 for i in xrange(n)] for j in xrange(n)]for i in xrange(n): dp[i][i] = 1for col i

2016-08-18 09:28:37 399

原创 HackerRank: Sam and sub-strings

题目链接分析考虑每一位数字对最终总和的贡献,画出表格分析小例子得到模式。代码s = raw_input()n = len(s)candies = 0mul = 1MOD = 1000000007for index in xrange(n - 1, -1, -1): candies = (candies + (ord(s[index]) - ord('0')) * mul *(ind

2016-08-17 18:30:07 527

原创 HackerRank: Bricks Game

题目链接分析本题使用动态规划的思想解决。dp[i]表示:若player从当前位置开始,能获得的最大分数。很明显,需要逆序构建dp数组。代码(Python 2.7)t = int(raw_input())for t_i in xrange(t): n = int(raw_input()) a = map(int, raw_input().split()) cum_sum = [

2016-08-17 13:30:37 376

原创 HackerRank: Equal

逆向思维:(1)题目问的是让我们“加”巧克力使得每个人最终巧克力数量一样。这等价于“减”巧克力使得每个人最终巧克力数量一样。(2)用“减”的方法,最终的目标是使得每个人的巧克力数量为原输入数组的最小值或者任意小于该值但不为负

2016-08-17 10:47:32 716 1

空空如也

空空如也

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

TA关注的人

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