Daily Archives: April 11, 2015


[leetcode] Simplify Path

Given an absolute path for a file (Unix-style), simplify it. For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c” click to show corner cases. Corner Cases: Did you consider the case where path = “/../”? In this case, you should return “/”. Another corner case is the […]


[leetcode] Add Binary

Add Binary Given two binary strings, return their sum (also a binary string). For example, a = “11” b = “1” Return “100”. 二进制加法,注意进位。和字符串访问时的末尾对齐。 class Solution { public: string addBinary(string a, string b) { if(a.empty()) return b; else if(b.empty()) return a; int carry = 0; string sum; int i = […]


[leetcode] Plus One

Plus One Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. Show Tags 注意进位,从vector末尾扫向开头。 class Solution { public: vector<int> plusOne(vector<int> &digits) { if(digits.size() == 0) return digits; […]