# 1、机器人能否返回原点

输入: "UD"



输入: "LL"



## 1.2、算法

### 1.2.1、算法1

 /**
* 方案2：计数 （推荐）
*/
public boolean judgeCircle2(String moves) {
int U = 0 , D = 0 , L = 0, R = 0 ;
for (int i = 0; i < moves.length(); i++) {
Character character = moves.charAt(i);
if (character == 'U'){
U++;
}
if (character == 'D'){
D++;
}
if (character == 'L'){
L++;
}
if (character == 'R'){
R++;
}
}
//上和下，左和右相等
return  U == D && L == R ;
}


### 1.2.2、算法2

  /**
* 方案1 List解决
*/
public boolean judgeCircle(String moves) {
Map<Character, Character> map = new HashMap<>();
map.put('U','D');
map.put('D','U');
map.put('R','L');
map.put('L','R');

List<Character> set = new ArrayList<>();
for (int i = 0; i < moves.length(); i++) {
Character key = moves.charAt(i);
Character value = map.get(key);
if (set.contains(key)){
set.remove(key);
}else {
}
}
return set.isEmpty();
}


## 1.3、测试

@Test
public void test() {
System.out.println(judgeCircle2("LDRRLRUULR"));
}
{"ft_lang_label":"__label__zh","ft_lang_prob":0.5427574,"math_prob":0.9912501,"size":1287,"snap":"2022-05-2022-21","text_gpt3_token_len":644,"char_repetition_ratio":0.12704599,"word_repetition_ratio":0.08092485,"special_character_ratio":0.3892774,"punctuation_ratio":0.23507462,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9714559,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-25T00:34:32Z\",\"WARC-Record-ID\":\"<urn:uuid:24dd983c-2594-4402-9b03-1d72f0e91f57>\",\"Content-Length\":\"33293\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5aa336f8-b606-41e0-ad65-c48969e33bd8>\",\"WARC-Concurrent-To\":\"<urn:uuid:f4813ecf-d5e9-4519-8062-cf0b91e1f88a>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"https://blog.healerjean.com/arithmetic/2015/01/01/%E4%BB%8A%E6%97%A5%E7%AE%97%E6%B3%95%E4%B9%8B_144_%E6%9C%BA%E5%99%A8%E4%BA%BA%E8%83%BD%E5%90%A6%E8%BF%94%E5%9B%9E%E5%8E%9F%E7%82%B9/\",\"WARC-Payload-Digest\":\"sha1:TD6NDVGIHTH2E72MRME2TRLK7KPGCABS\",\"WARC-Block-Digest\":\"sha1:WJEPI4ORS2WABC4HZA2SB255246Y5QSV\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662577757.82_warc_CC-MAIN-20220524233716-20220525023716-00080.warc.gz\"}"}