
LeetCode刷题
好雨知时节呀
热爱分享,热爱生活
展开
-
LeetCode: 387. 字符串中的第一个唯一字符
题目描述 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。 案例 s = "leetcode" 返回 0. s = "loveleetcode", 返回 2. 接口实现: class Solution { public: int firstUniqChar(string s) { int hashtable[256] = {0}; ...原创 2019-05-21 09:14:32 · 132 阅读 · 0 评论 -
位运算实现加减乘除运算(另类加减乘数)
当不可以使用加减乘数直接计算两个数字的结果的时候,那么我们可以使用位运算来计算这些结果,具体代码如下: 加法: // 递归求解 int add(int num1, int num2){ if (num2 == 0) return num1; int sum = num1 ^ num2; int carry = (num1 & num2) << 1; ret...原创 2019-06-10 10:54:26 · 268 阅读 · 0 评论