LeetCode-面试题 01.01. 判定字符是否唯一

/*
面试题 01.01. 判定字符是否唯一
实现一个算法,确定一个字符串 s 的所有字符是否全都不同。
*/
public:
    bool isUnique(std::string astr) {
        bool unique = true;
        std::vector<bool> book (26 * 2, false);
        for (int i = 0; i < astr.length(); ++i)
        {
            auto index = astr[i] - 'A';
            if (book[index])
            {
                unique = false;
                break;
            }
            else
            {
                book[index] = true;
            }
        }

        return unique;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
51单片机IINA219 测电流电压和功率。 #include "LCD1602\LCD1602.h" #include "INA219_DRV\INA219_DRV.h" #include "common\common.h" #define TH0_VALUE 0x4B #define TL0_VALUE 0xFF //50ms per cycle. sbit BtnRefreshMode = P3^2; bit RefreshRate = 0; //0: 0.8s, 1: 0.5s bit RefreshFlag = 0; void RefreshData(void) { unsigned short BusVolt, Current, Power; unsigned short OffsetCurrent, OffsetPower; BusVolt = INA219_GetBusVolt(); PrintChar(0, 0, BusVolt/10000+48); PrintChar(1, 0, (BusVolt000)/1000+48); PrintChar(3, 0, (BusVolt00)/100+48); PrintChar(4, 0, (BusVolt0)/10+48); PrintChar(5, 0, BusVolt+48); OffsetCurrent = (BusVolt >> 9) + 2; //Gather statistics of the measured current under various voltage conditions when no load is connected to the output port. Use Excel to do curve fitting. Current = INA219_GetCurrent(); if(Current > OffsetCurrent) Current -= OffsetCurrent; else Current = 0; PrintChar(10, 0, Current/1000+48); PrintChar(12, 0, (Current00)/100+48); PrintChar(13, 0, (Current0)/10+48); PrintChar(14, 0, Current+48); OffsetPower = ((BusVolt >> 3) * OffsetCurrent)/125 + 6; Power = INA219_GetPower(); if(Power > OffsetPower) Power -= OffsetPower; else Power = 0; PrintChar(0, 1, Power/10000+48); PrintChar(1, 1, (Power000)/1000+48); PrintChar(3, 1, (Power00)/100+48); PrintChar(4, 1, (Power0)/10+48); PrintChar(5, 1, Power+48); } int main(void) { INA219_Init(); LCD_Init(); TMOD &= 0xF0; TMOD |= 0x01; //Timer 0 works in Mode 1 (16-bit Timer). TH0 = TH0_VALUE; TL0 = TL0_VALUE; PrintChar(2, 0, '.'); PrintChar(6, 0, 'V'); PrintChar(11, 0, '.'); PrintChar(15, 0, 'A'); PrintChar(2, 1, '.'); PrintChar(6, 1, 'W'); PrintStr(10, 1, "R:0.8s"); RefreshData(); EA = 1; //Global Interrupt Enable ET0 = 1; //Timer 0 Interrupt Enable TR0 = 1; //Enable Timer 0. while(1) { if(RefreshFlag) { RefreshData(); RefreshFlag = 0; } if(BtnRefreshMode == 0) //If the

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值