# Monthly Archives: November 2015

## [leetcode] Range Sum Query 2D – Mutable1

Range Sum Query 2D – Mutable Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). The above rectangle (with the red border) is defined by (row1, col1) = (2, 1) and […]

## [leetcode]Range Sum Query – Mutable

Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. The update(i, val) function modifies nums by updating the element at index i to val. Example: Given nums = [1, 3, 5] sumRange(0, 2) -> 9 update(1, 2) sumRange(0, 2) […]

## [lintcode] Topological Sorting

Topological Sorting Medium Topological SortingShow result 25% Accepted Given an directed graph, a topological order of the graph nodes is defined as follow: For each directed edge A -> B in graph, A must before B in the order list. The first node in the order can be any node […]

Additive number is a positive integer whose digits can form additive sequence. A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of the preceding two. For example: “112358” is an additive number because […]

## [leetcode] Isomorphic Strings

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 with another character while preserving the order of characters. No two characters may map […]

## [leetcode] Implement Queue using Stacks

Implement Queue using Stacks Implement the following operations of a queue using stacks. push(x) — Push element x to the back of queue. pop() — Removes the element from in front of queue. peek() — Get the front element. empty() — Return whether the queue is empty. Notes: You must […]

## [leetcode] Kth Largest Element in an Array

Kth Largest Element in an Array Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, return 5. Note: You may assume k is always valid, […]

## [lintcode] Flatten Binary Tree to Linked List

Flatten Binary Tree to Linked List Flatten a binary tree to a fake “linked list” in pre-order traversal. Here we use the right pointer in TreeNode as the nextpointer in ListNode. Have you met this question in a real interview? Yes Example 1 \ 1 2 / \ \ 2 […]

## [lintcode] Longest Increasing Continuous subsequence II

Longest Increasing Continuous subsequence II Give you an integer matrix (with row size n, column size m)，find the longest increasing continuous subsequence in this matrix. (The definition of the longest increasing continuous subsequence here can start at any row or column and go up/down/right/left any direction). Have you met this […]

## [leetcode] One Edit Distance

One Edit Distance Given two strings S and T, determine if they are both one edit distance apart. two pointers. class Solution { public: bool isOneEditDistance(string s, string t) { int ls = s.size(); int lt = t.size(); if(abs(ls – lt) > 1) return false; int i = 0, j […]